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