@oasiz/sdk 1.3.0 → 1.4.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,24 +1,4 @@
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;
14
- }
15
- interface LogOverlayHandle {
16
- clear: () => void;
17
- destroy: () => void;
18
- hide: () => void;
19
- isVisible: () => boolean;
20
- show: () => void;
21
- }
22
2
  interface ScoreAnchor {
23
3
  raw: number;
24
4
  normalized: 100 | 300 | 600 | 950;
@@ -27,26 +7,81 @@ interface ScoreConfig {
27
7
  anchors: [ScoreAnchor, ScoreAnchor, ScoreAnchor, ScoreAnchor];
28
8
  }
29
9
  type GameState = Record<string, unknown>;
10
+ type StoreProductType = "non-consumable" | "consumable";
11
+ type StoreProductStatus = "active" | "disabled" | "archived";
12
+ type StoreEntitlementStatus = "active" | "consumed" | "revoked" | "refunded";
13
+ interface StoreManifestProduct {
14
+ description?: string | null;
15
+ jemPrice: number;
16
+ metadata?: Record<string, unknown>;
17
+ productId: string;
18
+ title: string;
19
+ type: StoreProductType;
20
+ }
21
+ interface StoreProduct {
22
+ description: string | null;
23
+ gameId: string;
24
+ jemPrice: number;
25
+ metadata: Record<string, unknown>;
26
+ productId: string;
27
+ status: StoreProductStatus;
28
+ title: string;
29
+ type: StoreProductType;
30
+ version: number;
31
+ }
32
+ interface StoreEntitlement {
33
+ gameId: string;
34
+ grantedAt: string | null;
35
+ lastEventId: string | null;
36
+ owned: boolean;
37
+ productId: string;
38
+ quantity: number;
39
+ status: StoreEntitlementStatus;
40
+ updatedAt: string;
41
+ }
42
+ interface StoreStateSnapshot {
43
+ catalogVersion: number;
44
+ entitlements: StoreEntitlement[];
45
+ gameId: string;
46
+ jemBalance: number;
47
+ products: StoreProduct[];
48
+ }
49
+ interface StorePurchaseSuccess {
50
+ attemptId: string;
51
+ entitlement: StoreEntitlement;
52
+ jemBalance: number;
53
+ ok: true;
54
+ state: StoreStateSnapshot;
55
+ transactionId: string;
56
+ }
57
+ interface StorePurchaseFailure {
58
+ attemptId: string;
59
+ code: "ALREADY_OWNED" | "INSUFFICIENT_JEMS" | "INVALID_PRODUCT" | "PRODUCT_DISABLED" | "INVALID_QUANTITY" | "ENTITLEMENT_EXHAUSTED" | "STALE_CATALOG_VERSION" | "UNAUTHORIZED";
60
+ jemBalance: number;
61
+ message: string;
62
+ ok: false;
63
+ state?: StoreStateSnapshot;
64
+ topUpIntentId?: string;
65
+ topUpRedirectUrl?: string;
66
+ }
67
+ type StorePurchaseResult = StorePurchaseSuccess | StorePurchaseFailure;
68
+ interface StoreConsumeSuccess {
69
+ entitlement: StoreEntitlement;
70
+ ok: true;
71
+ state: StoreStateSnapshot;
72
+ }
73
+ interface StoreConsumeFailure {
74
+ code: "INVALID_PRODUCT" | "INVALID_QUANTITY" | "NOT_CONSUMABLE" | "ENTITLEMENT_EXHAUSTED";
75
+ jemBalance: number;
76
+ message: string;
77
+ ok: false;
78
+ state?: StoreStateSnapshot;
79
+ }
80
+ type StoreConsumeResult = StoreConsumeSuccess | StoreConsumeFailure;
30
81
 
31
82
  declare function triggerHaptic(type: HapticType): void;
32
83
 
33
- declare function enableLogOverlay(options?: LogOverlayOptions): LogOverlayHandle;
34
-
35
- interface ShareRoomCodeOptions {
36
- inviteOverride?: boolean;
37
- }
38
- /**
39
- * Notify the platform of the active multiplayer room so friends can join.
40
- * Pass `{ inviteOverride: true }` when the game wants to hide the platform
41
- * invite pill and own the invite UI itself.
42
- */
43
- declare function shareRoomCode(roomCode: string | null, options?: ShareRoomCodeOptions): void;
44
- /**
45
- * Ask the platform to open the invite-friends modal for the current game room.
46
- * Only has effect when the platform has a room code (game has called shareRoomCode).
47
- * No-op when the bridge is unavailable (e.g. local development).
48
- */
49
- declare function openInviteModal(): void;
84
+ declare function shareRoomCode(roomCode: string | null): void;
50
85
  declare function getGameId(): string | undefined;
51
86
  declare function getRoomCode(): string | undefined;
52
87
  declare function getPlayerName(): string | undefined;
@@ -67,25 +102,46 @@ declare function onBackButton(callback: () => void): Unsubscribe;
67
102
  declare function onLeaveGame(callback: () => void): Unsubscribe;
68
103
  declare function leaveGame(): void;
69
104
 
105
+ declare function syncProducts(products: StoreManifestProduct[], expectedVersion?: number | null): Promise<StoreStateSnapshot>;
106
+ declare function getProducts(): Promise<StoreProduct[]>;
107
+ declare function getEntitlements(): Promise<StoreEntitlement[]>;
108
+ declare function hasEntitlement(productId: string): Promise<boolean>;
109
+ declare function getQuantity(productId: string): Promise<number>;
110
+ declare function purchase(productId: string, quantity?: number): Promise<StorePurchaseResult>;
111
+ declare function consume(productId: string, quantity?: number): Promise<StoreConsumeResult>;
112
+ declare function getJemBalance(): Promise<number>;
113
+ declare function onEntitlementsChanged(callback: (entitlements: StoreEntitlement[]) => void): () => void;
114
+ declare function onJemBalanceChanged(callback: (jemBalance: number) => void): () => void;
115
+
70
116
  declare const oasiz: {
71
117
  submitScore: typeof submitScore;
72
118
  emitScoreConfig: typeof emitScoreConfig;
73
119
  triggerHaptic: typeof triggerHaptic;
74
- enableLogOverlay: typeof enableLogOverlay;
75
120
  loadGameState: typeof loadGameState;
76
121
  saveGameState: typeof saveGameState;
77
122
  flushGameState: typeof flushGameState;
78
123
  shareRoomCode: typeof shareRoomCode;
79
- openInviteModal: typeof openInviteModal;
80
124
  onPause: typeof onPause;
81
125
  onResume: typeof onResume;
82
126
  onBackButton: typeof onBackButton;
83
127
  onLeaveGame: typeof onLeaveGame;
84
128
  leaveGame: typeof leaveGame;
129
+ store: {
130
+ syncProducts: typeof syncProducts;
131
+ getProducts: typeof getProducts;
132
+ getEntitlements: typeof getEntitlements;
133
+ hasEntitlement: typeof hasEntitlement;
134
+ getQuantity: typeof getQuantity;
135
+ purchase: typeof purchase;
136
+ consume: typeof consume;
137
+ getJemBalance: typeof getJemBalance;
138
+ onEntitlementsChanged: typeof onEntitlementsChanged;
139
+ onJemBalanceChanged: typeof onJemBalanceChanged;
140
+ };
85
141
  readonly gameId: string | undefined;
86
142
  readonly roomCode: string | undefined;
87
143
  readonly playerName: string | undefined;
88
144
  readonly playerAvatar: string | undefined;
89
145
  };
90
146
 
91
- export { type GameState, type HapticType, type LogOverlayEntry, type LogOverlayHandle, type LogOverlayLevel, type LogOverlayOptions, type ScoreAnchor, type ScoreConfig, type ShareRoomCodeOptions, type Unsubscribe, emitScoreConfig, enableLogOverlay, flushGameState, getGameId, getPlayerAvatar, getPlayerName, getRoomCode, leaveGame, loadGameState, oasiz, onBackButton, onLeaveGame, onPause, onResume, openInviteModal, saveGameState, shareRoomCode, submitScore, triggerHaptic };
147
+ export { type GameState, type HapticType, type ScoreAnchor, type ScoreConfig, 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, shareRoomCode, submitScore, syncProducts, triggerHaptic };
package/dist/index.d.ts CHANGED
@@ -1,24 +1,4 @@
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;
14
- }
15
- interface LogOverlayHandle {
16
- clear: () => void;
17
- destroy: () => void;
18
- hide: () => void;
19
- isVisible: () => boolean;
20
- show: () => void;
21
- }
22
2
  interface ScoreAnchor {
23
3
  raw: number;
24
4
  normalized: 100 | 300 | 600 | 950;
@@ -27,26 +7,81 @@ interface ScoreConfig {
27
7
  anchors: [ScoreAnchor, ScoreAnchor, ScoreAnchor, ScoreAnchor];
28
8
  }
29
9
  type GameState = Record<string, unknown>;
10
+ type StoreProductType = "non-consumable" | "consumable";
11
+ type StoreProductStatus = "active" | "disabled" | "archived";
12
+ type StoreEntitlementStatus = "active" | "consumed" | "revoked" | "refunded";
13
+ interface StoreManifestProduct {
14
+ description?: string | null;
15
+ jemPrice: number;
16
+ metadata?: Record<string, unknown>;
17
+ productId: string;
18
+ title: string;
19
+ type: StoreProductType;
20
+ }
21
+ interface StoreProduct {
22
+ description: string | null;
23
+ gameId: string;
24
+ jemPrice: number;
25
+ metadata: Record<string, unknown>;
26
+ productId: string;
27
+ status: StoreProductStatus;
28
+ title: string;
29
+ type: StoreProductType;
30
+ version: number;
31
+ }
32
+ interface StoreEntitlement {
33
+ gameId: string;
34
+ grantedAt: string | null;
35
+ lastEventId: string | null;
36
+ owned: boolean;
37
+ productId: string;
38
+ quantity: number;
39
+ status: StoreEntitlementStatus;
40
+ updatedAt: string;
41
+ }
42
+ interface StoreStateSnapshot {
43
+ catalogVersion: number;
44
+ entitlements: StoreEntitlement[];
45
+ gameId: string;
46
+ jemBalance: number;
47
+ products: StoreProduct[];
48
+ }
49
+ interface StorePurchaseSuccess {
50
+ attemptId: string;
51
+ entitlement: StoreEntitlement;
52
+ jemBalance: number;
53
+ ok: true;
54
+ state: StoreStateSnapshot;
55
+ transactionId: string;
56
+ }
57
+ interface StorePurchaseFailure {
58
+ attemptId: string;
59
+ code: "ALREADY_OWNED" | "INSUFFICIENT_JEMS" | "INVALID_PRODUCT" | "PRODUCT_DISABLED" | "INVALID_QUANTITY" | "ENTITLEMENT_EXHAUSTED" | "STALE_CATALOG_VERSION" | "UNAUTHORIZED";
60
+ jemBalance: number;
61
+ message: string;
62
+ ok: false;
63
+ state?: StoreStateSnapshot;
64
+ topUpIntentId?: string;
65
+ topUpRedirectUrl?: string;
66
+ }
67
+ type StorePurchaseResult = StorePurchaseSuccess | StorePurchaseFailure;
68
+ interface StoreConsumeSuccess {
69
+ entitlement: StoreEntitlement;
70
+ ok: true;
71
+ state: StoreStateSnapshot;
72
+ }
73
+ interface StoreConsumeFailure {
74
+ code: "INVALID_PRODUCT" | "INVALID_QUANTITY" | "NOT_CONSUMABLE" | "ENTITLEMENT_EXHAUSTED";
75
+ jemBalance: number;
76
+ message: string;
77
+ ok: false;
78
+ state?: StoreStateSnapshot;
79
+ }
80
+ type StoreConsumeResult = StoreConsumeSuccess | StoreConsumeFailure;
30
81
 
31
82
  declare function triggerHaptic(type: HapticType): void;
32
83
 
33
- declare function enableLogOverlay(options?: LogOverlayOptions): LogOverlayHandle;
34
-
35
- interface ShareRoomCodeOptions {
36
- inviteOverride?: boolean;
37
- }
38
- /**
39
- * Notify the platform of the active multiplayer room so friends can join.
40
- * Pass `{ inviteOverride: true }` when the game wants to hide the platform
41
- * invite pill and own the invite UI itself.
42
- */
43
- declare function shareRoomCode(roomCode: string | null, options?: ShareRoomCodeOptions): void;
44
- /**
45
- * Ask the platform to open the invite-friends modal for the current game room.
46
- * Only has effect when the platform has a room code (game has called shareRoomCode).
47
- * No-op when the bridge is unavailable (e.g. local development).
48
- */
49
- declare function openInviteModal(): void;
84
+ declare function shareRoomCode(roomCode: string | null): void;
50
85
  declare function getGameId(): string | undefined;
51
86
  declare function getRoomCode(): string | undefined;
52
87
  declare function getPlayerName(): string | undefined;
@@ -67,25 +102,46 @@ declare function onBackButton(callback: () => void): Unsubscribe;
67
102
  declare function onLeaveGame(callback: () => void): Unsubscribe;
68
103
  declare function leaveGame(): void;
69
104
 
105
+ declare function syncProducts(products: StoreManifestProduct[], expectedVersion?: number | null): Promise<StoreStateSnapshot>;
106
+ declare function getProducts(): Promise<StoreProduct[]>;
107
+ declare function getEntitlements(): Promise<StoreEntitlement[]>;
108
+ declare function hasEntitlement(productId: string): Promise<boolean>;
109
+ declare function getQuantity(productId: string): Promise<number>;
110
+ declare function purchase(productId: string, quantity?: number): Promise<StorePurchaseResult>;
111
+ declare function consume(productId: string, quantity?: number): Promise<StoreConsumeResult>;
112
+ declare function getJemBalance(): Promise<number>;
113
+ declare function onEntitlementsChanged(callback: (entitlements: StoreEntitlement[]) => void): () => void;
114
+ declare function onJemBalanceChanged(callback: (jemBalance: number) => void): () => void;
115
+
70
116
  declare const oasiz: {
71
117
  submitScore: typeof submitScore;
72
118
  emitScoreConfig: typeof emitScoreConfig;
73
119
  triggerHaptic: typeof triggerHaptic;
74
- enableLogOverlay: typeof enableLogOverlay;
75
120
  loadGameState: typeof loadGameState;
76
121
  saveGameState: typeof saveGameState;
77
122
  flushGameState: typeof flushGameState;
78
123
  shareRoomCode: typeof shareRoomCode;
79
- openInviteModal: typeof openInviteModal;
80
124
  onPause: typeof onPause;
81
125
  onResume: typeof onResume;
82
126
  onBackButton: typeof onBackButton;
83
127
  onLeaveGame: typeof onLeaveGame;
84
128
  leaveGame: typeof leaveGame;
129
+ store: {
130
+ syncProducts: typeof syncProducts;
131
+ getProducts: typeof getProducts;
132
+ getEntitlements: typeof getEntitlements;
133
+ hasEntitlement: typeof hasEntitlement;
134
+ getQuantity: typeof getQuantity;
135
+ purchase: typeof purchase;
136
+ consume: typeof consume;
137
+ getJemBalance: typeof getJemBalance;
138
+ onEntitlementsChanged: typeof onEntitlementsChanged;
139
+ onJemBalanceChanged: typeof onJemBalanceChanged;
140
+ };
85
141
  readonly gameId: string | undefined;
86
142
  readonly roomCode: string | undefined;
87
143
  readonly playerName: string | undefined;
88
144
  readonly playerAvatar: string | undefined;
89
145
  };
90
146
 
91
- export { type GameState, type HapticType, type LogOverlayEntry, type LogOverlayHandle, type LogOverlayLevel, type LogOverlayOptions, type ScoreAnchor, type ScoreConfig, type ShareRoomCodeOptions, type Unsubscribe, emitScoreConfig, enableLogOverlay, flushGameState, getGameId, getPlayerAvatar, getPlayerName, getRoomCode, leaveGame, loadGameState, oasiz, onBackButton, onLeaveGame, onPause, onResume, openInviteModal, saveGameState, shareRoomCode, submitScore, triggerHaptic };
147
+ export { type GameState, type HapticType, type ScoreAnchor, type ScoreConfig, 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, shareRoomCode, submitScore, syncProducts, triggerHaptic };