@oasiz/sdk 1.6.1 → 1.7.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/README.md +85 -464
- package/dist/index.cjs +231 -1943
- package/dist/index.d.cts +102 -248
- package/dist/index.d.ts +102 -248
- package/dist/index.js +220 -1932
- package/package.json +4 -14
package/dist/index.d.ts
CHANGED
|
@@ -1,66 +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
1
|
type HapticType = "light" | "medium" | "heavy" | "success" | "error";
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
level: LogOverlayLevel;
|
|
49
|
-
message: string;
|
|
50
|
-
timestamp: number;
|
|
2
|
+
interface ScoreAnchor {
|
|
3
|
+
raw: number;
|
|
4
|
+
normalized: 100 | 300 | 600 | 950;
|
|
51
5
|
}
|
|
52
|
-
interface
|
|
53
|
-
|
|
54
|
-
enabled?: boolean;
|
|
55
|
-
maxEntries?: number;
|
|
56
|
-
title?: string;
|
|
57
|
-
}
|
|
58
|
-
interface LogOverlayHandle {
|
|
59
|
-
clear: () => void;
|
|
60
|
-
destroy: () => void;
|
|
61
|
-
hide: () => void;
|
|
62
|
-
isVisible: () => boolean;
|
|
63
|
-
show: () => void;
|
|
6
|
+
interface ScoreConfig {
|
|
7
|
+
anchors: [ScoreAnchor, ScoreAnchor, ScoreAnchor, ScoreAnchor];
|
|
64
8
|
}
|
|
65
9
|
type GameState = Record<string, unknown>;
|
|
66
10
|
interface ShareRequest {
|
|
@@ -68,166 +12,88 @@ interface ShareRequest {
|
|
|
68
12
|
score?: number;
|
|
69
13
|
text?: string;
|
|
70
14
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
newScore: number;
|
|
141
|
-
previousWeeklyScore: number;
|
|
142
|
-
newWeeklyScore: number;
|
|
143
|
-
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;
|
|
144
84
|
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Fetch the authenticated player's character, including a TexturePacker /
|
|
148
|
-
* Phaser-style texture atlas describing the baked sprite image.
|
|
149
|
-
*
|
|
150
|
-
* Returns:
|
|
151
|
-
* - `null` when the user has no character composition yet, OR
|
|
152
|
-
* - `null` when the host bridge is unavailable (local dev / unauthenticated)
|
|
153
|
-
*
|
|
154
|
-
* The host transparently caches and proxies to `GET /api/sdk/me/character`,
|
|
155
|
-
* so calling this multiple times in a session is cheap. The returned
|
|
156
|
-
* `imageUrl` is content-addressed (R2 key derives from the composition
|
|
157
|
-
* hash), so games can safely cache the downloaded texture by `compositionCode`.
|
|
158
|
-
*
|
|
159
|
-
* Example (Phaser):
|
|
160
|
-
*
|
|
161
|
-
* const character = await oasiz.getPlayerCharacter();
|
|
162
|
-
* if (!character) return;
|
|
163
|
-
* const atlas = character.textureAtlas;
|
|
164
|
-
* scene.load.image("player-tex", atlas.imageUrl);
|
|
165
|
-
* scene.load.atlas("player", atlas.imageUrl, {
|
|
166
|
-
* frames: Object.fromEntries(
|
|
167
|
-
* atlas.frames.map((f) => [f.name, { frame: { x: f.x, y: f.y, w: f.width, h: f.height } }]),
|
|
168
|
-
* ),
|
|
169
|
-
* });
|
|
170
|
-
*/
|
|
171
|
-
declare function getPlayerCharacter(): Promise<PlayerCharacter | null>;
|
|
85
|
+
type StoreConsumeResult = StoreConsumeSuccess | StoreConsumeFailure;
|
|
172
86
|
|
|
173
87
|
declare function triggerHaptic(type: HapticType): void;
|
|
174
88
|
|
|
175
|
-
declare function
|
|
176
|
-
|
|
177
|
-
interface ShareRoomCodeOptions {
|
|
178
|
-
inviteOverride?: boolean;
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* Notify the platform of the active multiplayer room so friends can join.
|
|
182
|
-
* Pass `{ inviteOverride: true }` when the game wants to hide the platform
|
|
183
|
-
* invite pill and own the invite UI itself.
|
|
184
|
-
*/
|
|
185
|
-
declare function shareRoomCode(roomCode: string | null, options?: ShareRoomCodeOptions): void;
|
|
186
|
-
/**
|
|
187
|
-
* Ask the platform to open the invite-friends modal for the current game room.
|
|
188
|
-
* Only has effect when the platform has a room code (game has called shareRoomCode).
|
|
189
|
-
* No-op when the bridge is unavailable (e.g. local development).
|
|
190
|
-
*/
|
|
191
|
-
declare function openInviteModal(): void;
|
|
89
|
+
declare function shareRoomCode(roomCode: string | null): void;
|
|
192
90
|
declare function getGameId(): string | undefined;
|
|
193
91
|
declare function getRoomCode(): string | undefined;
|
|
194
|
-
/**
|
|
195
|
-
* Stable, unique, opaque identifier for the authenticated player, injected
|
|
196
|
-
* by the platform. Safe to use as a primary key for save slots, matchmaking,
|
|
197
|
-
* per-player analytics, or anywhere you need a reliable per-user key —
|
|
198
|
-
* unlike `getPlayerName()` (mutable, not unique).
|
|
199
|
-
*
|
|
200
|
-
* Mirrors the backend's `playerId` field returned by `GET /api/sdk/me`
|
|
201
|
-
* (= the Better Auth `user.id`). Returns `undefined` when the platform
|
|
202
|
-
* has not injected an identity (e.g. unauthenticated preview).
|
|
203
|
-
*/
|
|
204
|
-
declare function getPlayerId(): string | undefined;
|
|
205
92
|
declare function getPlayerName(): string | undefined;
|
|
206
93
|
declare function getPlayerAvatar(): string | undefined;
|
|
207
94
|
|
|
208
95
|
declare function submitScore(score: number): void;
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* Add (or subtract) `delta` from the player's current score for this game.
|
|
212
|
-
* The new score is clamped to >= 0 server-side.
|
|
213
|
-
*
|
|
214
|
-
* Unlike `submitScore()` (which is high-water and only ever raises the
|
|
215
|
-
* score), this endpoint always overwrites the row. Use it for game models
|
|
216
|
-
* where the leaderboard tracks an accumulator, balance, or persistent state
|
|
217
|
-
* instead of a single best-run value.
|
|
218
|
-
*
|
|
219
|
-
* Returns the resulting score values, or `null` when the bridge is
|
|
220
|
-
* unavailable. The integer must be a non-zero integer (positive or negative).
|
|
221
|
-
*/
|
|
222
|
-
declare function addScore(delta: number): Promise<ScoreEditResult | null>;
|
|
223
|
-
/**
|
|
224
|
-
* Force the player's score to an absolute value (clamped to >= 0).
|
|
225
|
-
*
|
|
226
|
-
* Same overwrite semantics as `addScore`. Use when the game has computed
|
|
227
|
-
* the authoritative score locally (e.g. after offline play) and wants to
|
|
228
|
-
* sync it back to the leaderboard.
|
|
229
|
-
*/
|
|
230
|
-
declare function setScore(score: number): Promise<ScoreEditResult | null>;
|
|
96
|
+
declare function emitScoreConfig(config: ScoreConfig): void;
|
|
231
97
|
|
|
232
98
|
declare function share(options: ShareRequest): Promise<void>;
|
|
233
99
|
|
|
@@ -239,63 +105,51 @@ type Unsubscribe = () => void;
|
|
|
239
105
|
declare function onPause(callback: () => void): Unsubscribe;
|
|
240
106
|
declare function onResume(callback: () => void): Unsubscribe;
|
|
241
107
|
|
|
242
|
-
interface BackButtonTestingOptions {
|
|
243
|
-
/**
|
|
244
|
-
* When true, pressing Escape dispatches the same event the host app sends for
|
|
245
|
-
* back actions. Defaults to true.
|
|
246
|
-
*/
|
|
247
|
-
keyboard?: boolean;
|
|
248
|
-
/**
|
|
249
|
-
* When true, the SDK traps one browser-history entry while back override is
|
|
250
|
-
* active, so the browser Back button can be used for local testing. Defaults
|
|
251
|
-
* to true.
|
|
252
|
-
*/
|
|
253
|
-
browserHistory?: boolean;
|
|
254
|
-
/** Log setup details to the console. Defaults to false. */
|
|
255
|
-
log?: boolean;
|
|
256
|
-
}
|
|
257
|
-
interface BackButtonTestingHandle {
|
|
258
|
-
destroy: () => void;
|
|
259
|
-
isBackOverrideActive: () => boolean;
|
|
260
|
-
triggerBack: () => void;
|
|
261
|
-
triggerLeave: () => void;
|
|
262
|
-
}
|
|
263
|
-
declare function enableBackButtonTesting(options?: BackButtonTestingOptions): BackButtonTestingHandle;
|
|
264
108
|
declare function onBackButton(callback: () => void): Unsubscribe;
|
|
265
109
|
declare function onLeaveGame(callback: () => void): Unsubscribe;
|
|
266
110
|
declare function leaveGame(): void;
|
|
267
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
|
+
|
|
268
123
|
declare const oasiz: {
|
|
269
124
|
submitScore: typeof submitScore;
|
|
270
|
-
|
|
271
|
-
setScore: typeof setScore;
|
|
272
|
-
getPlayerCharacter: typeof getPlayerCharacter;
|
|
125
|
+
emitScoreConfig: typeof emitScoreConfig;
|
|
273
126
|
share: typeof share;
|
|
274
127
|
triggerHaptic: typeof triggerHaptic;
|
|
275
|
-
enableLogOverlay: typeof enableLogOverlay;
|
|
276
128
|
loadGameState: typeof loadGameState;
|
|
277
129
|
saveGameState: typeof saveGameState;
|
|
278
130
|
flushGameState: typeof flushGameState;
|
|
279
131
|
shareRoomCode: typeof shareRoomCode;
|
|
280
|
-
openInviteModal: typeof openInviteModal;
|
|
281
132
|
onPause: typeof onPause;
|
|
282
133
|
onResume: typeof onResume;
|
|
283
|
-
getSafeAreaTop: typeof getSafeAreaTop;
|
|
284
|
-
getViewportInsets: typeof getViewportInsets;
|
|
285
|
-
setLeaderboardVisible: typeof setLeaderboardVisible;
|
|
286
|
-
getGraphicsPerformance: typeof getGraphicsPerformance;
|
|
287
|
-
enableBackButtonTesting: typeof enableBackButtonTesting;
|
|
288
134
|
onBackButton: typeof onBackButton;
|
|
289
135
|
onLeaveGame: typeof onLeaveGame;
|
|
290
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
|
+
};
|
|
291
149
|
readonly gameId: string | undefined;
|
|
292
150
|
readonly roomCode: string | undefined;
|
|
293
|
-
readonly playerId: string | undefined;
|
|
294
151
|
readonly playerName: string | undefined;
|
|
295
152
|
readonly playerAvatar: string | undefined;
|
|
296
|
-
readonly safeAreaTop: number;
|
|
297
|
-
readonly viewportInsets: ViewportInsets;
|
|
298
|
-
readonly graphicsPerformance: GraphicsPerformanceMetric;
|
|
299
153
|
};
|
|
300
154
|
|
|
301
|
-
export { type
|
|
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 };
|