@oasiz/sdk 1.5.5 → 1.6.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,23 +1,10 @@
1
1
  type HapticType = "light" | "medium" | "heavy" | "success" | "error";
2
- type LogOverlayLevel = "debug" | "log" | "info" | "warn" | "error";
3
- interface LogOverlayEntry {
4
- id: number;
5
- level: LogOverlayLevel;
6
- message: string;
7
- timestamp: number;
8
- }
9
- interface LogOverlayOptions {
10
- collapsed?: boolean;
11
- enabled?: boolean;
12
- maxEntries?: number;
13
- title?: string;
2
+ interface ScoreAnchor {
3
+ raw: number;
4
+ normalized: 100 | 300 | 600 | 950;
14
5
  }
15
- interface LogOverlayHandle {
16
- clear: () => void;
17
- destroy: () => void;
18
- hide: () => void;
19
- isVisible: () => boolean;
20
- show: () => void;
6
+ interface ScoreConfig {
7
+ anchors: [ScoreAnchor, ScoreAnchor, ScoreAnchor, ScoreAnchor];
21
8
  }
22
9
  type GameState = Record<string, unknown>;
23
10
  interface ShareRequest {
@@ -25,166 +12,88 @@ interface ShareRequest {
25
12
  score?: number;
26
13
  text?: string;
27
14
  }
28
- /**
29
- * One frame in a texture atlas. Coordinates are in pixels, top-left origin
30
- * (matches HTML canvas / WebGL texture coordinates after Y-flip).
31
- */
32
- interface TextureAtlasFrame {
33
- name: string;
34
- x: number;
35
- y: number;
36
- width: number;
37
- height: number;
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;
38
36
  }
39
- /**
40
- * Per-direction frame indexes inside an animation. `left` is either an
41
- * integer index or the literal string `"mirror"`, indicating the renderer
42
- * should mirror the right-facing frame instead of using a dedicated one.
43
- */
44
- interface FacingFrameMap {
45
- front: number;
46
- back: number;
47
- right: number;
48
- left: number | "mirror";
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;
49
46
  }
50
- /**
51
- * One named animation in a texture atlas. `frames` is the playback-ordered
52
- * list of frame names; resolve each name against the parent atlas's
53
- * `frames` array to get pixel coordinates.
54
- */
55
- interface TextureAtlasAnimation {
56
- animationId: string;
57
- role: string | null;
58
- group: string | null;
59
- direction: string | null;
60
- frameRate: number;
61
- frames: string[];
62
- facingFrameMap: FacingFrameMap | null;
47
+ interface StoreStateSnapshot {
48
+ catalogVersion: number;
49
+ entitlements: StoreEntitlement[];
50
+ gameId: string;
51
+ jemBalance: number;
52
+ products: StoreProduct[];
63
53
  }
64
- /**
65
- * TexturePacker / Phaser-style texture atlas describing a baked sprite
66
- * image. Drop-in compatible with Phaser via `addAtlas(key, img, atlas)`
67
- * after a tiny shape transform; usable directly in custom GL renderers.
68
- */
69
- interface TextureAtlas {
70
- imageUrl: string;
71
- imageWidth: number;
72
- imageHeight: number;
73
- frames: TextureAtlasFrame[];
74
- animations: TextureAtlasAnimation[];
54
+ interface StorePurchaseSuccess {
55
+ attemptId: string;
56
+ entitlement: StoreEntitlement;
57
+ jemBalance: number;
58
+ ok: true;
59
+ state: StoreStateSnapshot;
60
+ transactionId: string;
75
61
  }
76
- /**
77
- * The authenticated player's character, returned by `getPlayerCharacter()`.
78
- * `editorTextureAtlas` is the higher-detail variant intended for character
79
- * previews / customizer UI and may be `null`.
80
- */
81
- interface PlayerCharacter {
82
- characterName: string | null;
83
- baseCharacterId: string;
84
- compositionCode: string;
85
- textureAtlas: TextureAtlas;
86
- editorTextureAtlas: TextureAtlas | null;
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;
87
71
  }
88
- /**
89
- * Result of `addScore(delta)` / `setScore(score)`. Returns `null` when the
90
- * host bridge is unavailable (e.g. local development) or when the backend
91
- * refused the request; production code should treat `null` as "no change
92
- * was persisted, do not update local UI".
93
- */
94
- interface ScoreEditResult {
95
- playerId: string;
96
- previousScore: number;
97
- newScore: number;
98
- previousWeeklyScore: number;
99
- newWeeklyScore: number;
100
- normalizedScore: number | null;
72
+ type StorePurchaseResult = StorePurchaseSuccess | StorePurchaseFailure;
73
+ interface StoreConsumeSuccess {
74
+ entitlement: StoreEntitlement;
75
+ ok: true;
76
+ state: StoreStateSnapshot;
101
77
  }
102
-
103
- /**
104
- * Fetch the authenticated player's character, including a TexturePacker /
105
- * Phaser-style texture atlas describing the baked sprite image.
106
- *
107
- * Returns:
108
- * - `null` when the user has no character composition yet, OR
109
- * - `null` when the host bridge is unavailable (local dev / unauthenticated)
110
- *
111
- * The host transparently caches and proxies to `GET /api/sdk/me/character`,
112
- * so calling this multiple times in a session is cheap. The returned
113
- * `imageUrl` is content-addressed (R2 key derives from the composition
114
- * hash), so games can safely cache the downloaded texture by `compositionCode`.
115
- *
116
- * Example (Phaser):
117
- *
118
- * const character = await oasiz.getPlayerCharacter();
119
- * if (!character) return;
120
- * const atlas = character.textureAtlas;
121
- * scene.load.image("player-tex", atlas.imageUrl);
122
- * scene.load.atlas("player", atlas.imageUrl, {
123
- * frames: Object.fromEntries(
124
- * atlas.frames.map((f) => [f.name, { frame: { x: f.x, y: f.y, w: f.width, h: f.height } }]),
125
- * ),
126
- * });
127
- */
128
- declare function getPlayerCharacter(): Promise<PlayerCharacter | null>;
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;
84
+ }
85
+ type StoreConsumeResult = StoreConsumeSuccess | StoreConsumeFailure;
129
86
 
130
87
  declare function triggerHaptic(type: HapticType): void;
131
88
 
132
- declare function enableLogOverlay(options?: LogOverlayOptions): LogOverlayHandle;
133
-
134
- interface ShareRoomCodeOptions {
135
- inviteOverride?: boolean;
136
- }
137
- /**
138
- * Notify the platform of the active multiplayer room so friends can join.
139
- * Pass `{ inviteOverride: true }` when the game wants to hide the platform
140
- * invite pill and own the invite UI itself.
141
- */
142
- declare function shareRoomCode(roomCode: string | null, options?: ShareRoomCodeOptions): void;
143
- /**
144
- * Ask the platform to open the invite-friends modal for the current game room.
145
- * Only has effect when the platform has a room code (game has called shareRoomCode).
146
- * No-op when the bridge is unavailable (e.g. local development).
147
- */
148
- declare function openInviteModal(): void;
89
+ declare function shareRoomCode(roomCode: string | null): void;
149
90
  declare function getGameId(): string | undefined;
150
91
  declare function getRoomCode(): string | undefined;
151
- /**
152
- * Stable, unique, opaque identifier for the authenticated player, injected
153
- * by the platform. Safe to use as a primary key for save slots, matchmaking,
154
- * per-player analytics, or anywhere you need a reliable per-user key —
155
- * unlike `getPlayerName()` (mutable, not unique).
156
- *
157
- * Mirrors the backend's `playerId` field returned by `GET /api/sdk/me`
158
- * (= the Better Auth `user.id`). Returns `undefined` when the platform
159
- * has not injected an identity (e.g. unauthenticated preview).
160
- */
161
- declare function getPlayerId(): string | undefined;
162
92
  declare function getPlayerName(): string | undefined;
163
93
  declare function getPlayerAvatar(): string | undefined;
164
94
 
165
95
  declare function submitScore(score: number): void;
166
-
167
- /**
168
- * Add (or subtract) `delta` from the player's current score for this game.
169
- * The new score is clamped to >= 0 server-side.
170
- *
171
- * Unlike `submitScore()` (which is high-water and only ever raises the
172
- * score), this endpoint always overwrites the row. Use it for game models
173
- * where the leaderboard tracks an accumulator, balance, or persistent state
174
- * instead of a single best-run value.
175
- *
176
- * Returns the resulting score values, or `null` when the bridge is
177
- * unavailable. The integer must be a non-zero integer (positive or negative).
178
- */
179
- declare function addScore(delta: number): Promise<ScoreEditResult | null>;
180
- /**
181
- * Force the player's score to an absolute value (clamped to >= 0).
182
- *
183
- * Same overwrite semantics as `addScore`. Use when the game has computed
184
- * the authoritative score locally (e.g. after offline play) and wants to
185
- * sync it back to the leaderboard.
186
- */
187
- declare function setScore(score: number): Promise<ScoreEditResult | null>;
96
+ declare function emitScoreConfig(config: ScoreConfig): void;
188
97
 
189
98
  declare function share(options: ShareRequest): Promise<void>;
190
99
 
@@ -196,45 +105,51 @@ type Unsubscribe = () => void;
196
105
  declare function onPause(callback: () => void): Unsubscribe;
197
106
  declare function onResume(callback: () => void): Unsubscribe;
198
107
 
199
- /**
200
- * Top safe-area inset as a percentage of the viewport height (0–100).
201
- * The host may expose CSS pixels via `getSafeAreaTop` / `__OASIZ_SAFE_AREA_TOP__`
202
- * (converted using `window.innerHeight`), or percentages via
203
- * `getSafeAreaTopPercent` / `__OASIZ_SAFE_AREA_TOP_PERCENT__`.
204
- */
205
- declare function getSafeAreaTop(): number;
206
- declare function setLeaderboardVisible(visible: boolean): void;
207
-
208
108
  declare function onBackButton(callback: () => void): Unsubscribe;
209
109
  declare function onLeaveGame(callback: () => void): Unsubscribe;
210
110
  declare function leaveGame(): void;
211
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
+
212
123
  declare const oasiz: {
213
124
  submitScore: typeof submitScore;
214
- addScore: typeof addScore;
215
- setScore: typeof setScore;
216
- getPlayerCharacter: typeof getPlayerCharacter;
125
+ emitScoreConfig: typeof emitScoreConfig;
217
126
  share: typeof share;
218
127
  triggerHaptic: typeof triggerHaptic;
219
- enableLogOverlay: typeof enableLogOverlay;
220
128
  loadGameState: typeof loadGameState;
221
129
  saveGameState: typeof saveGameState;
222
130
  flushGameState: typeof flushGameState;
223
131
  shareRoomCode: typeof shareRoomCode;
224
- openInviteModal: typeof openInviteModal;
225
132
  onPause: typeof onPause;
226
133
  onResume: typeof onResume;
227
- getSafeAreaTop: typeof getSafeAreaTop;
228
- setLeaderboardVisible: typeof setLeaderboardVisible;
229
134
  onBackButton: typeof onBackButton;
230
135
  onLeaveGame: typeof onLeaveGame;
231
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
+ };
232
149
  readonly gameId: string | undefined;
233
150
  readonly roomCode: string | undefined;
234
- readonly playerId: string | undefined;
235
151
  readonly playerName: string | undefined;
236
152
  readonly playerAvatar: string | undefined;
237
- readonly safeAreaTop: number;
238
153
  };
239
154
 
240
- export { type FacingFrameMap, type GameState, 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, addScore, enableLogOverlay, flushGameState, getGameId, getPlayerAvatar, getPlayerCharacter, getPlayerId, getPlayerName, getRoomCode, getSafeAreaTop, 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 };
package/dist/index.d.ts CHANGED
@@ -1,23 +1,10 @@
1
1
  type HapticType = "light" | "medium" | "heavy" | "success" | "error";
2
- type LogOverlayLevel = "debug" | "log" | "info" | "warn" | "error";
3
- interface LogOverlayEntry {
4
- id: number;
5
- level: LogOverlayLevel;
6
- message: string;
7
- timestamp: number;
8
- }
9
- interface LogOverlayOptions {
10
- collapsed?: boolean;
11
- enabled?: boolean;
12
- maxEntries?: number;
13
- title?: string;
2
+ interface ScoreAnchor {
3
+ raw: number;
4
+ normalized: 100 | 300 | 600 | 950;
14
5
  }
15
- interface LogOverlayHandle {
16
- clear: () => void;
17
- destroy: () => void;
18
- hide: () => void;
19
- isVisible: () => boolean;
20
- show: () => void;
6
+ interface ScoreConfig {
7
+ anchors: [ScoreAnchor, ScoreAnchor, ScoreAnchor, ScoreAnchor];
21
8
  }
22
9
  type GameState = Record<string, unknown>;
23
10
  interface ShareRequest {
@@ -25,166 +12,88 @@ interface ShareRequest {
25
12
  score?: number;
26
13
  text?: string;
27
14
  }
28
- /**
29
- * One frame in a texture atlas. Coordinates are in pixels, top-left origin
30
- * (matches HTML canvas / WebGL texture coordinates after Y-flip).
31
- */
32
- interface TextureAtlasFrame {
33
- name: string;
34
- x: number;
35
- y: number;
36
- width: number;
37
- height: number;
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;
38
36
  }
39
- /**
40
- * Per-direction frame indexes inside an animation. `left` is either an
41
- * integer index or the literal string `"mirror"`, indicating the renderer
42
- * should mirror the right-facing frame instead of using a dedicated one.
43
- */
44
- interface FacingFrameMap {
45
- front: number;
46
- back: number;
47
- right: number;
48
- left: number | "mirror";
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;
49
46
  }
50
- /**
51
- * One named animation in a texture atlas. `frames` is the playback-ordered
52
- * list of frame names; resolve each name against the parent atlas's
53
- * `frames` array to get pixel coordinates.
54
- */
55
- interface TextureAtlasAnimation {
56
- animationId: string;
57
- role: string | null;
58
- group: string | null;
59
- direction: string | null;
60
- frameRate: number;
61
- frames: string[];
62
- facingFrameMap: FacingFrameMap | null;
47
+ interface StoreStateSnapshot {
48
+ catalogVersion: number;
49
+ entitlements: StoreEntitlement[];
50
+ gameId: string;
51
+ jemBalance: number;
52
+ products: StoreProduct[];
63
53
  }
64
- /**
65
- * TexturePacker / Phaser-style texture atlas describing a baked sprite
66
- * image. Drop-in compatible with Phaser via `addAtlas(key, img, atlas)`
67
- * after a tiny shape transform; usable directly in custom GL renderers.
68
- */
69
- interface TextureAtlas {
70
- imageUrl: string;
71
- imageWidth: number;
72
- imageHeight: number;
73
- frames: TextureAtlasFrame[];
74
- animations: TextureAtlasAnimation[];
54
+ interface StorePurchaseSuccess {
55
+ attemptId: string;
56
+ entitlement: StoreEntitlement;
57
+ jemBalance: number;
58
+ ok: true;
59
+ state: StoreStateSnapshot;
60
+ transactionId: string;
75
61
  }
76
- /**
77
- * The authenticated player's character, returned by `getPlayerCharacter()`.
78
- * `editorTextureAtlas` is the higher-detail variant intended for character
79
- * previews / customizer UI and may be `null`.
80
- */
81
- interface PlayerCharacter {
82
- characterName: string | null;
83
- baseCharacterId: string;
84
- compositionCode: string;
85
- textureAtlas: TextureAtlas;
86
- editorTextureAtlas: TextureAtlas | null;
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;
87
71
  }
88
- /**
89
- * Result of `addScore(delta)` / `setScore(score)`. Returns `null` when the
90
- * host bridge is unavailable (e.g. local development) or when the backend
91
- * refused the request; production code should treat `null` as "no change
92
- * was persisted, do not update local UI".
93
- */
94
- interface ScoreEditResult {
95
- playerId: string;
96
- previousScore: number;
97
- newScore: number;
98
- previousWeeklyScore: number;
99
- newWeeklyScore: number;
100
- normalizedScore: number | null;
72
+ type StorePurchaseResult = StorePurchaseSuccess | StorePurchaseFailure;
73
+ interface StoreConsumeSuccess {
74
+ entitlement: StoreEntitlement;
75
+ ok: true;
76
+ state: StoreStateSnapshot;
101
77
  }
102
-
103
- /**
104
- * Fetch the authenticated player's character, including a TexturePacker /
105
- * Phaser-style texture atlas describing the baked sprite image.
106
- *
107
- * Returns:
108
- * - `null` when the user has no character composition yet, OR
109
- * - `null` when the host bridge is unavailable (local dev / unauthenticated)
110
- *
111
- * The host transparently caches and proxies to `GET /api/sdk/me/character`,
112
- * so calling this multiple times in a session is cheap. The returned
113
- * `imageUrl` is content-addressed (R2 key derives from the composition
114
- * hash), so games can safely cache the downloaded texture by `compositionCode`.
115
- *
116
- * Example (Phaser):
117
- *
118
- * const character = await oasiz.getPlayerCharacter();
119
- * if (!character) return;
120
- * const atlas = character.textureAtlas;
121
- * scene.load.image("player-tex", atlas.imageUrl);
122
- * scene.load.atlas("player", atlas.imageUrl, {
123
- * frames: Object.fromEntries(
124
- * atlas.frames.map((f) => [f.name, { frame: { x: f.x, y: f.y, w: f.width, h: f.height } }]),
125
- * ),
126
- * });
127
- */
128
- declare function getPlayerCharacter(): Promise<PlayerCharacter | null>;
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;
84
+ }
85
+ type StoreConsumeResult = StoreConsumeSuccess | StoreConsumeFailure;
129
86
 
130
87
  declare function triggerHaptic(type: HapticType): void;
131
88
 
132
- declare function enableLogOverlay(options?: LogOverlayOptions): LogOverlayHandle;
133
-
134
- interface ShareRoomCodeOptions {
135
- inviteOverride?: boolean;
136
- }
137
- /**
138
- * Notify the platform of the active multiplayer room so friends can join.
139
- * Pass `{ inviteOverride: true }` when the game wants to hide the platform
140
- * invite pill and own the invite UI itself.
141
- */
142
- declare function shareRoomCode(roomCode: string | null, options?: ShareRoomCodeOptions): void;
143
- /**
144
- * Ask the platform to open the invite-friends modal for the current game room.
145
- * Only has effect when the platform has a room code (game has called shareRoomCode).
146
- * No-op when the bridge is unavailable (e.g. local development).
147
- */
148
- declare function openInviteModal(): void;
89
+ declare function shareRoomCode(roomCode: string | null): void;
149
90
  declare function getGameId(): string | undefined;
150
91
  declare function getRoomCode(): string | undefined;
151
- /**
152
- * Stable, unique, opaque identifier for the authenticated player, injected
153
- * by the platform. Safe to use as a primary key for save slots, matchmaking,
154
- * per-player analytics, or anywhere you need a reliable per-user key —
155
- * unlike `getPlayerName()` (mutable, not unique).
156
- *
157
- * Mirrors the backend's `playerId` field returned by `GET /api/sdk/me`
158
- * (= the Better Auth `user.id`). Returns `undefined` when the platform
159
- * has not injected an identity (e.g. unauthenticated preview).
160
- */
161
- declare function getPlayerId(): string | undefined;
162
92
  declare function getPlayerName(): string | undefined;
163
93
  declare function getPlayerAvatar(): string | undefined;
164
94
 
165
95
  declare function submitScore(score: number): void;
166
-
167
- /**
168
- * Add (or subtract) `delta` from the player's current score for this game.
169
- * The new score is clamped to >= 0 server-side.
170
- *
171
- * Unlike `submitScore()` (which is high-water and only ever raises the
172
- * score), this endpoint always overwrites the row. Use it for game models
173
- * where the leaderboard tracks an accumulator, balance, or persistent state
174
- * instead of a single best-run value.
175
- *
176
- * Returns the resulting score values, or `null` when the bridge is
177
- * unavailable. The integer must be a non-zero integer (positive or negative).
178
- */
179
- declare function addScore(delta: number): Promise<ScoreEditResult | null>;
180
- /**
181
- * Force the player's score to an absolute value (clamped to >= 0).
182
- *
183
- * Same overwrite semantics as `addScore`. Use when the game has computed
184
- * the authoritative score locally (e.g. after offline play) and wants to
185
- * sync it back to the leaderboard.
186
- */
187
- declare function setScore(score: number): Promise<ScoreEditResult | null>;
96
+ declare function emitScoreConfig(config: ScoreConfig): void;
188
97
 
189
98
  declare function share(options: ShareRequest): Promise<void>;
190
99
 
@@ -196,45 +105,51 @@ type Unsubscribe = () => void;
196
105
  declare function onPause(callback: () => void): Unsubscribe;
197
106
  declare function onResume(callback: () => void): Unsubscribe;
198
107
 
199
- /**
200
- * Top safe-area inset as a percentage of the viewport height (0–100).
201
- * The host may expose CSS pixels via `getSafeAreaTop` / `__OASIZ_SAFE_AREA_TOP__`
202
- * (converted using `window.innerHeight`), or percentages via
203
- * `getSafeAreaTopPercent` / `__OASIZ_SAFE_AREA_TOP_PERCENT__`.
204
- */
205
- declare function getSafeAreaTop(): number;
206
- declare function setLeaderboardVisible(visible: boolean): void;
207
-
208
108
  declare function onBackButton(callback: () => void): Unsubscribe;
209
109
  declare function onLeaveGame(callback: () => void): Unsubscribe;
210
110
  declare function leaveGame(): void;
211
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
+
212
123
  declare const oasiz: {
213
124
  submitScore: typeof submitScore;
214
- addScore: typeof addScore;
215
- setScore: typeof setScore;
216
- getPlayerCharacter: typeof getPlayerCharacter;
125
+ emitScoreConfig: typeof emitScoreConfig;
217
126
  share: typeof share;
218
127
  triggerHaptic: typeof triggerHaptic;
219
- enableLogOverlay: typeof enableLogOverlay;
220
128
  loadGameState: typeof loadGameState;
221
129
  saveGameState: typeof saveGameState;
222
130
  flushGameState: typeof flushGameState;
223
131
  shareRoomCode: typeof shareRoomCode;
224
- openInviteModal: typeof openInviteModal;
225
132
  onPause: typeof onPause;
226
133
  onResume: typeof onResume;
227
- getSafeAreaTop: typeof getSafeAreaTop;
228
- setLeaderboardVisible: typeof setLeaderboardVisible;
229
134
  onBackButton: typeof onBackButton;
230
135
  onLeaveGame: typeof onLeaveGame;
231
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
+ };
232
149
  readonly gameId: string | undefined;
233
150
  readonly roomCode: string | undefined;
234
- readonly playerId: string | undefined;
235
151
  readonly playerName: string | undefined;
236
152
  readonly playerAvatar: string | undefined;
237
- readonly safeAreaTop: number;
238
153
  };
239
154
 
240
- export { type FacingFrameMap, type GameState, 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, addScore, enableLogOverlay, flushGameState, getGameId, getPlayerAvatar, getPlayerCharacter, getPlayerId, getPlayerName, getRoomCode, getSafeAreaTop, 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 };