@hyve-sdk/js 1.2.2 → 1.3.1-canary.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 +96 -0
- package/dist/index.d.mts +216 -6
- package/dist/index.d.ts +216 -6
- package/dist/index.js +391 -37
- package/dist/index.mjs +387 -37
- package/package.json +13 -12
package/README.md
CHANGED
|
@@ -20,6 +20,7 @@ pnpm add @hyve-sdk/js
|
|
|
20
20
|
- **API Integration**: Authenticated API calls with JWT token support
|
|
21
21
|
- **Inventory Management**: Built-in methods for user inventory operations
|
|
22
22
|
- **Telemetry Tracking**: Session-based analytics and event tracking
|
|
23
|
+
- **Native Bridge**: Type-safe communication with React Native WebView apps
|
|
23
24
|
- **Security Utilities**: Domain validation and referrer checking
|
|
24
25
|
- **URL Parameter Parsing**: Easy extraction of authentication parameters
|
|
25
26
|
- **UUID Generation**: Built-in UUID v4 generation
|
|
@@ -282,6 +283,101 @@ if (item.metadata) {
|
|
|
282
283
|
- JWT token must be available (via `hyve-access` URL parameter)
|
|
283
284
|
- User must be authenticated
|
|
284
285
|
|
|
286
|
+
## Native Bridge (React Native WebView)
|
|
287
|
+
|
|
288
|
+
Provides type-safe bidirectional communication between your web application and the React Native mobile app.
|
|
289
|
+
|
|
290
|
+
### Quick Start
|
|
291
|
+
|
|
292
|
+
```typescript
|
|
293
|
+
import { NativeBridge, NativeMessageType } from "@hyve-sdk/js";
|
|
294
|
+
|
|
295
|
+
// Initialize on app start
|
|
296
|
+
if (NativeBridge.isNativeContext()) {
|
|
297
|
+
NativeBridge.initialize();
|
|
298
|
+
}
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
### Check IAP Availability
|
|
302
|
+
|
|
303
|
+
Request information about In-App Purchase availability:
|
|
304
|
+
|
|
305
|
+
```typescript
|
|
306
|
+
// Register response handler
|
|
307
|
+
NativeBridge.on("IAP_AVAILABILITY_RESULT", (payload) => {
|
|
308
|
+
if (payload.available) {
|
|
309
|
+
console.log("IAP is available on this device");
|
|
310
|
+
// Show purchase UI
|
|
311
|
+
} else {
|
|
312
|
+
console.log("IAP is not available");
|
|
313
|
+
// Hide purchase features
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
// Send request
|
|
318
|
+
NativeBridge.checkIAPAvailability();
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
### Request Push Notifications
|
|
322
|
+
|
|
323
|
+
Request notification permissions from the native app:
|
|
324
|
+
|
|
325
|
+
```typescript
|
|
326
|
+
// Register response handlers
|
|
327
|
+
NativeBridge.on("PUSH_PERMISSION_GRANTED", (payload) => {
|
|
328
|
+
console.log("Push notifications enabled");
|
|
329
|
+
console.log("Token:", payload?.token);
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
NativeBridge.on("PUSH_PERMISSION_DENIED", () => {
|
|
333
|
+
console.log("Push notifications disabled");
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
// Send request
|
|
337
|
+
NativeBridge.requestNotificationPermission();
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
### Send Custom Messages
|
|
341
|
+
|
|
342
|
+
Send custom messages to the native app:
|
|
343
|
+
|
|
344
|
+
```typescript
|
|
345
|
+
// Send message with payload
|
|
346
|
+
NativeBridge.send("CUSTOM_EVENT", {
|
|
347
|
+
action: "open_settings",
|
|
348
|
+
data: { setting: "notifications" }
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
// Listen for custom responses
|
|
352
|
+
NativeBridge.on("CUSTOM_RESPONSE", (payload) => {
|
|
353
|
+
console.log("Received:", payload);
|
|
354
|
+
});
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
### Built-in Message Types
|
|
358
|
+
|
|
359
|
+
**Web → Native:**
|
|
360
|
+
- `CHECK_IAP_AVAILABILITY` - Check if IAP is available
|
|
361
|
+
- `REQUEST_NOTIFICATION_PERMISSION` - Request push notification permission
|
|
362
|
+
|
|
363
|
+
**Native → Web:**
|
|
364
|
+
- `IAP_AVAILABILITY_RESULT` - Response with IAP availability
|
|
365
|
+
- `PUSH_PERMISSION_GRANTED` - Push permission granted
|
|
366
|
+
- `PUSH_PERMISSION_DENIED` - Push permission denied
|
|
367
|
+
|
|
368
|
+
### API Reference
|
|
369
|
+
|
|
370
|
+
- `NativeBridge.isNativeContext()` - Check if running in React Native WebView
|
|
371
|
+
- `NativeBridge.initialize()` - Initialize message listener
|
|
372
|
+
- `NativeBridge.send(type, payload?)` - Send message to native
|
|
373
|
+
- `NativeBridge.on(type, handler)` - Register message handler
|
|
374
|
+
- `NativeBridge.off(type)` - Unregister message handler
|
|
375
|
+
- `NativeBridge.clearHandlers()` - Clear all handlers
|
|
376
|
+
- `NativeBridge.checkIAPAvailability()` - Helper for IAP check
|
|
377
|
+
- `NativeBridge.requestNotificationPermission()` - Helper for notification permission
|
|
378
|
+
|
|
379
|
+
For complete documentation, see [docs/NATIVE_BRIDGE.md](./docs/NATIVE_BRIDGE.md).
|
|
380
|
+
|
|
285
381
|
## Client Methods Reference
|
|
286
382
|
|
|
287
383
|
### Authentication
|
package/dist/index.d.mts
CHANGED
|
@@ -167,6 +167,53 @@ declare class HyveClient {
|
|
|
167
167
|
reset(): void;
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
+
/**
|
|
171
|
+
* Logger utility for the Hyve SDK
|
|
172
|
+
* Automatically enabled in development (NODE_ENV !== 'production')
|
|
173
|
+
*/
|
|
174
|
+
type LogLevel = "debug" | "info" | "warn" | "error";
|
|
175
|
+
declare class Logger {
|
|
176
|
+
private config;
|
|
177
|
+
constructor();
|
|
178
|
+
/**
|
|
179
|
+
* Initialize logger configuration based on NODE_ENV
|
|
180
|
+
*/
|
|
181
|
+
private initializeConfig;
|
|
182
|
+
/**
|
|
183
|
+
* Set which log levels to display
|
|
184
|
+
*/
|
|
185
|
+
setLevels(levels: LogLevel[]): void;
|
|
186
|
+
/**
|
|
187
|
+
* Check if logging is enabled
|
|
188
|
+
*/
|
|
189
|
+
isEnabled(): boolean;
|
|
190
|
+
/**
|
|
191
|
+
* Internal log method
|
|
192
|
+
*/
|
|
193
|
+
private log;
|
|
194
|
+
/**
|
|
195
|
+
* Log a debug message
|
|
196
|
+
*/
|
|
197
|
+
debug(...args: unknown[]): void;
|
|
198
|
+
/**
|
|
199
|
+
* Log an info message
|
|
200
|
+
*/
|
|
201
|
+
info(...args: unknown[]): void;
|
|
202
|
+
/**
|
|
203
|
+
* Log a warning message
|
|
204
|
+
*/
|
|
205
|
+
warn(...args: unknown[]): void;
|
|
206
|
+
/**
|
|
207
|
+
* Log an error message
|
|
208
|
+
*/
|
|
209
|
+
error(...args: unknown[]): void;
|
|
210
|
+
/**
|
|
211
|
+
* Create a child logger with a specific prefix
|
|
212
|
+
*/
|
|
213
|
+
child(prefix: string): Logger;
|
|
214
|
+
}
|
|
215
|
+
declare const logger: Logger;
|
|
216
|
+
|
|
170
217
|
/**
|
|
171
218
|
* Parses URL search parameters and returns commonly used values
|
|
172
219
|
* @param searchParams URLSearchParams object or string
|
|
@@ -218,11 +265,6 @@ declare function verifyAuthentication(params: {
|
|
|
218
265
|
method: "modern" | "legacy" | "none";
|
|
219
266
|
error?: string;
|
|
220
267
|
};
|
|
221
|
-
/**
|
|
222
|
-
* Generates a random UUID (v4) using the uuid library
|
|
223
|
-
* @returns A string containing a randomly generated UUID
|
|
224
|
-
*/
|
|
225
|
-
declare function generateUUID(): string;
|
|
226
268
|
/**
|
|
227
269
|
* Checks if the current domain is in the list of allowed domains
|
|
228
270
|
* @param allowedDomains Array of allowed domains or a single domain string
|
|
@@ -230,4 +272,172 @@ declare function generateUUID(): string;
|
|
|
230
272
|
*/
|
|
231
273
|
declare function isDomainAllowed(allowedDomains?: string | string[], hostname?: string): boolean;
|
|
232
274
|
|
|
233
|
-
|
|
275
|
+
/**
|
|
276
|
+
* Message structure for WebView to Native communication
|
|
277
|
+
*/
|
|
278
|
+
interface NativeMessage<T = any> {
|
|
279
|
+
type: string;
|
|
280
|
+
payload?: T;
|
|
281
|
+
timestamp?: number;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Message types for native communication
|
|
285
|
+
*/
|
|
286
|
+
declare enum NativeMessageType {
|
|
287
|
+
/** Check if In-App Purchases are available on the device */
|
|
288
|
+
CHECK_IAP_AVAILABILITY = "CHECK_IAP_AVAILABILITY",
|
|
289
|
+
/** Request notification permission from the native app */
|
|
290
|
+
REQUEST_NOTIFICATION_PERMISSION = "REQUEST_NOTIFICATION_PERMISSION",
|
|
291
|
+
/** Request available products for a game */
|
|
292
|
+
GET_PRODUCTS = "GET_PRODUCTS",
|
|
293
|
+
/** Initiate a purchase */
|
|
294
|
+
PURCHASE = "PURCHASE",
|
|
295
|
+
/** Response to CHECK_IAP_AVAILABILITY request */
|
|
296
|
+
IAP_AVAILABILITY_RESULT = "IAP_AVAILABILITY_RESULT",
|
|
297
|
+
/** Push notification permission was granted */
|
|
298
|
+
PUSH_PERMISSION_GRANTED = "PUSH_PERMISSION_GRANTED",
|
|
299
|
+
/** Push notification permission was denied */
|
|
300
|
+
PUSH_PERMISSION_DENIED = "PUSH_PERMISSION_DENIED",
|
|
301
|
+
/** Response with available products */
|
|
302
|
+
PRODUCTS_RESULT = "PRODUCTS_RESULT",
|
|
303
|
+
/** Purchase completed successfully */
|
|
304
|
+
PURCHASE_COMPLETE = "PURCHASE_COMPLETE",
|
|
305
|
+
/** Purchase failed or was cancelled */
|
|
306
|
+
PURCHASE_ERROR = "PURCHASE_ERROR"
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Message handler function type for receiving messages from native
|
|
310
|
+
*/
|
|
311
|
+
type NativeMessageHandler<T = any> = (payload: T) => void | Promise<void>;
|
|
312
|
+
/**
|
|
313
|
+
* NativeBridge - Provides utilities for WebView to React Native communication
|
|
314
|
+
*
|
|
315
|
+
* @example
|
|
316
|
+
* // Send message to React Native
|
|
317
|
+
* NativeBridge.send(NativeMessageType.CHECK_IAP_AVAILABILITY);
|
|
318
|
+
*
|
|
319
|
+
* // Listen for messages from React Native
|
|
320
|
+
* NativeBridge.on("PUSH_PERMISSION_GRANTED", (payload) => {
|
|
321
|
+
* console.log("Permission granted:", payload);
|
|
322
|
+
* });
|
|
323
|
+
*
|
|
324
|
+
* // Check if running in React Native WebView
|
|
325
|
+
* if (NativeBridge.isNativeContext()) {
|
|
326
|
+
* NativeBridge.checkIAPAvailability();
|
|
327
|
+
* }
|
|
328
|
+
*/
|
|
329
|
+
declare class NativeBridge {
|
|
330
|
+
private static handlers;
|
|
331
|
+
private static isInitialized;
|
|
332
|
+
/**
|
|
333
|
+
* Checks if the app is running inside a React Native WebView
|
|
334
|
+
*/
|
|
335
|
+
static isNativeContext(): boolean;
|
|
336
|
+
/**
|
|
337
|
+
* Initializes the native bridge message listener
|
|
338
|
+
* Call this once when your app starts
|
|
339
|
+
*/
|
|
340
|
+
static initialize(): void;
|
|
341
|
+
/**
|
|
342
|
+
* Handles incoming messages from React Native
|
|
343
|
+
*/
|
|
344
|
+
private static handleNativeMessage;
|
|
345
|
+
/**
|
|
346
|
+
* Sends a message to React Native
|
|
347
|
+
* @param type Message type
|
|
348
|
+
* @param payload Optional payload data
|
|
349
|
+
*/
|
|
350
|
+
static send<T = any>(type: string, payload?: T): void;
|
|
351
|
+
/**
|
|
352
|
+
* Registers a handler for messages from React Native
|
|
353
|
+
* @param type Message type to listen for
|
|
354
|
+
* @param handler Function to call when message is received
|
|
355
|
+
*/
|
|
356
|
+
static on<T = any>(type: string, handler: NativeMessageHandler<T>): void;
|
|
357
|
+
/**
|
|
358
|
+
* Unregisters a handler for a specific message type
|
|
359
|
+
* @param type Message type to stop listening for
|
|
360
|
+
*/
|
|
361
|
+
static off(type: string): void;
|
|
362
|
+
/**
|
|
363
|
+
* Clears all registered handlers
|
|
364
|
+
*/
|
|
365
|
+
static clearHandlers(): void;
|
|
366
|
+
/**
|
|
367
|
+
* Checks if In-App Purchases are available on the device
|
|
368
|
+
* The native app will respond with a message containing availability status
|
|
369
|
+
*
|
|
370
|
+
* @example
|
|
371
|
+
* // Listen for the response
|
|
372
|
+
* NativeBridge.on("IAP_AVAILABILITY_RESULT", (payload) => {
|
|
373
|
+
* console.log("IAP available:", payload.available);
|
|
374
|
+
* });
|
|
375
|
+
*
|
|
376
|
+
* // Send the request
|
|
377
|
+
* NativeBridge.checkIAPAvailability();
|
|
378
|
+
*/
|
|
379
|
+
static checkIAPAvailability(): void;
|
|
380
|
+
/**
|
|
381
|
+
* Requests notification permission from the native app
|
|
382
|
+
* The native app will respond with PUSH_PERMISSION_GRANTED or PUSH_PERMISSION_DENIED
|
|
383
|
+
*
|
|
384
|
+
* @example
|
|
385
|
+
* // Listen for the response
|
|
386
|
+
* NativeBridge.on("PUSH_PERMISSION_GRANTED", () => {
|
|
387
|
+
* console.log("Permission granted");
|
|
388
|
+
* });
|
|
389
|
+
*
|
|
390
|
+
* NativeBridge.on("PUSH_PERMISSION_DENIED", () => {
|
|
391
|
+
* console.log("Permission denied");
|
|
392
|
+
* });
|
|
393
|
+
*
|
|
394
|
+
* // Send the request
|
|
395
|
+
* NativeBridge.requestNotificationPermission();
|
|
396
|
+
*/
|
|
397
|
+
static requestNotificationPermission(): void;
|
|
398
|
+
/**
|
|
399
|
+
* Requests available products for a specific game
|
|
400
|
+
* The native app will respond with PRODUCTS_RESULT containing product details
|
|
401
|
+
*
|
|
402
|
+
* @param gameId - The game ID to fetch products for
|
|
403
|
+
*
|
|
404
|
+
* @example
|
|
405
|
+
* // Listen for the response
|
|
406
|
+
* NativeBridge.on("PRODUCTS_RESULT", (payload) => {
|
|
407
|
+
* console.log("Products:", payload.products);
|
|
408
|
+
* });
|
|
409
|
+
*
|
|
410
|
+
* // Send the request
|
|
411
|
+
* NativeBridge.getProducts(123);
|
|
412
|
+
*/
|
|
413
|
+
static getProducts(gameId: number): void;
|
|
414
|
+
/**
|
|
415
|
+
* Initiates a purchase for a specific product
|
|
416
|
+
* The native app will respond with PURCHASE_COMPLETE or PURCHASE_ERROR
|
|
417
|
+
*
|
|
418
|
+
* @param productId - The product ID to purchase
|
|
419
|
+
* @param userId - The user ID making the purchase
|
|
420
|
+
*
|
|
421
|
+
* @example
|
|
422
|
+
* // Listen for responses
|
|
423
|
+
* NativeBridge.on("PURCHASE_COMPLETE", (payload) => {
|
|
424
|
+
* console.log("Purchase successful:", payload.productId);
|
|
425
|
+
* });
|
|
426
|
+
*
|
|
427
|
+
* NativeBridge.on("PURCHASE_ERROR", (payload) => {
|
|
428
|
+
* console.error("Purchase failed:", payload.error);
|
|
429
|
+
* });
|
|
430
|
+
*
|
|
431
|
+
* // Initiate purchase
|
|
432
|
+
* NativeBridge.purchase("product_123", "user_456");
|
|
433
|
+
*/
|
|
434
|
+
static purchase(productId: string, userId: string): void;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* Generates a random UUID (v4) using the uuid library
|
|
439
|
+
* @returns A string containing a randomly generated UUID
|
|
440
|
+
*/
|
|
441
|
+
declare function generateUUID(): string;
|
|
442
|
+
|
|
443
|
+
export { HyveClient, type Inventory, type InventoryItem, Logger, NativeBridge, type NativeMessage, type NativeMessageHandler, NativeMessageType, type TelemetryAdditionalData, type TelemetryConfig, type TelemetryEvent, generateUUID, handleVerifyMessage, isDomainAllowed, logger, parseUrlParams, validateSignature, verifyAuthentication, verifyHyveToken };
|
package/dist/index.d.ts
CHANGED
|
@@ -167,6 +167,53 @@ declare class HyveClient {
|
|
|
167
167
|
reset(): void;
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
+
/**
|
|
171
|
+
* Logger utility for the Hyve SDK
|
|
172
|
+
* Automatically enabled in development (NODE_ENV !== 'production')
|
|
173
|
+
*/
|
|
174
|
+
type LogLevel = "debug" | "info" | "warn" | "error";
|
|
175
|
+
declare class Logger {
|
|
176
|
+
private config;
|
|
177
|
+
constructor();
|
|
178
|
+
/**
|
|
179
|
+
* Initialize logger configuration based on NODE_ENV
|
|
180
|
+
*/
|
|
181
|
+
private initializeConfig;
|
|
182
|
+
/**
|
|
183
|
+
* Set which log levels to display
|
|
184
|
+
*/
|
|
185
|
+
setLevels(levels: LogLevel[]): void;
|
|
186
|
+
/**
|
|
187
|
+
* Check if logging is enabled
|
|
188
|
+
*/
|
|
189
|
+
isEnabled(): boolean;
|
|
190
|
+
/**
|
|
191
|
+
* Internal log method
|
|
192
|
+
*/
|
|
193
|
+
private log;
|
|
194
|
+
/**
|
|
195
|
+
* Log a debug message
|
|
196
|
+
*/
|
|
197
|
+
debug(...args: unknown[]): void;
|
|
198
|
+
/**
|
|
199
|
+
* Log an info message
|
|
200
|
+
*/
|
|
201
|
+
info(...args: unknown[]): void;
|
|
202
|
+
/**
|
|
203
|
+
* Log a warning message
|
|
204
|
+
*/
|
|
205
|
+
warn(...args: unknown[]): void;
|
|
206
|
+
/**
|
|
207
|
+
* Log an error message
|
|
208
|
+
*/
|
|
209
|
+
error(...args: unknown[]): void;
|
|
210
|
+
/**
|
|
211
|
+
* Create a child logger with a specific prefix
|
|
212
|
+
*/
|
|
213
|
+
child(prefix: string): Logger;
|
|
214
|
+
}
|
|
215
|
+
declare const logger: Logger;
|
|
216
|
+
|
|
170
217
|
/**
|
|
171
218
|
* Parses URL search parameters and returns commonly used values
|
|
172
219
|
* @param searchParams URLSearchParams object or string
|
|
@@ -218,11 +265,6 @@ declare function verifyAuthentication(params: {
|
|
|
218
265
|
method: "modern" | "legacy" | "none";
|
|
219
266
|
error?: string;
|
|
220
267
|
};
|
|
221
|
-
/**
|
|
222
|
-
* Generates a random UUID (v4) using the uuid library
|
|
223
|
-
* @returns A string containing a randomly generated UUID
|
|
224
|
-
*/
|
|
225
|
-
declare function generateUUID(): string;
|
|
226
268
|
/**
|
|
227
269
|
* Checks if the current domain is in the list of allowed domains
|
|
228
270
|
* @param allowedDomains Array of allowed domains or a single domain string
|
|
@@ -230,4 +272,172 @@ declare function generateUUID(): string;
|
|
|
230
272
|
*/
|
|
231
273
|
declare function isDomainAllowed(allowedDomains?: string | string[], hostname?: string): boolean;
|
|
232
274
|
|
|
233
|
-
|
|
275
|
+
/**
|
|
276
|
+
* Message structure for WebView to Native communication
|
|
277
|
+
*/
|
|
278
|
+
interface NativeMessage<T = any> {
|
|
279
|
+
type: string;
|
|
280
|
+
payload?: T;
|
|
281
|
+
timestamp?: number;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Message types for native communication
|
|
285
|
+
*/
|
|
286
|
+
declare enum NativeMessageType {
|
|
287
|
+
/** Check if In-App Purchases are available on the device */
|
|
288
|
+
CHECK_IAP_AVAILABILITY = "CHECK_IAP_AVAILABILITY",
|
|
289
|
+
/** Request notification permission from the native app */
|
|
290
|
+
REQUEST_NOTIFICATION_PERMISSION = "REQUEST_NOTIFICATION_PERMISSION",
|
|
291
|
+
/** Request available products for a game */
|
|
292
|
+
GET_PRODUCTS = "GET_PRODUCTS",
|
|
293
|
+
/** Initiate a purchase */
|
|
294
|
+
PURCHASE = "PURCHASE",
|
|
295
|
+
/** Response to CHECK_IAP_AVAILABILITY request */
|
|
296
|
+
IAP_AVAILABILITY_RESULT = "IAP_AVAILABILITY_RESULT",
|
|
297
|
+
/** Push notification permission was granted */
|
|
298
|
+
PUSH_PERMISSION_GRANTED = "PUSH_PERMISSION_GRANTED",
|
|
299
|
+
/** Push notification permission was denied */
|
|
300
|
+
PUSH_PERMISSION_DENIED = "PUSH_PERMISSION_DENIED",
|
|
301
|
+
/** Response with available products */
|
|
302
|
+
PRODUCTS_RESULT = "PRODUCTS_RESULT",
|
|
303
|
+
/** Purchase completed successfully */
|
|
304
|
+
PURCHASE_COMPLETE = "PURCHASE_COMPLETE",
|
|
305
|
+
/** Purchase failed or was cancelled */
|
|
306
|
+
PURCHASE_ERROR = "PURCHASE_ERROR"
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Message handler function type for receiving messages from native
|
|
310
|
+
*/
|
|
311
|
+
type NativeMessageHandler<T = any> = (payload: T) => void | Promise<void>;
|
|
312
|
+
/**
|
|
313
|
+
* NativeBridge - Provides utilities for WebView to React Native communication
|
|
314
|
+
*
|
|
315
|
+
* @example
|
|
316
|
+
* // Send message to React Native
|
|
317
|
+
* NativeBridge.send(NativeMessageType.CHECK_IAP_AVAILABILITY);
|
|
318
|
+
*
|
|
319
|
+
* // Listen for messages from React Native
|
|
320
|
+
* NativeBridge.on("PUSH_PERMISSION_GRANTED", (payload) => {
|
|
321
|
+
* console.log("Permission granted:", payload);
|
|
322
|
+
* });
|
|
323
|
+
*
|
|
324
|
+
* // Check if running in React Native WebView
|
|
325
|
+
* if (NativeBridge.isNativeContext()) {
|
|
326
|
+
* NativeBridge.checkIAPAvailability();
|
|
327
|
+
* }
|
|
328
|
+
*/
|
|
329
|
+
declare class NativeBridge {
|
|
330
|
+
private static handlers;
|
|
331
|
+
private static isInitialized;
|
|
332
|
+
/**
|
|
333
|
+
* Checks if the app is running inside a React Native WebView
|
|
334
|
+
*/
|
|
335
|
+
static isNativeContext(): boolean;
|
|
336
|
+
/**
|
|
337
|
+
* Initializes the native bridge message listener
|
|
338
|
+
* Call this once when your app starts
|
|
339
|
+
*/
|
|
340
|
+
static initialize(): void;
|
|
341
|
+
/**
|
|
342
|
+
* Handles incoming messages from React Native
|
|
343
|
+
*/
|
|
344
|
+
private static handleNativeMessage;
|
|
345
|
+
/**
|
|
346
|
+
* Sends a message to React Native
|
|
347
|
+
* @param type Message type
|
|
348
|
+
* @param payload Optional payload data
|
|
349
|
+
*/
|
|
350
|
+
static send<T = any>(type: string, payload?: T): void;
|
|
351
|
+
/**
|
|
352
|
+
* Registers a handler for messages from React Native
|
|
353
|
+
* @param type Message type to listen for
|
|
354
|
+
* @param handler Function to call when message is received
|
|
355
|
+
*/
|
|
356
|
+
static on<T = any>(type: string, handler: NativeMessageHandler<T>): void;
|
|
357
|
+
/**
|
|
358
|
+
* Unregisters a handler for a specific message type
|
|
359
|
+
* @param type Message type to stop listening for
|
|
360
|
+
*/
|
|
361
|
+
static off(type: string): void;
|
|
362
|
+
/**
|
|
363
|
+
* Clears all registered handlers
|
|
364
|
+
*/
|
|
365
|
+
static clearHandlers(): void;
|
|
366
|
+
/**
|
|
367
|
+
* Checks if In-App Purchases are available on the device
|
|
368
|
+
* The native app will respond with a message containing availability status
|
|
369
|
+
*
|
|
370
|
+
* @example
|
|
371
|
+
* // Listen for the response
|
|
372
|
+
* NativeBridge.on("IAP_AVAILABILITY_RESULT", (payload) => {
|
|
373
|
+
* console.log("IAP available:", payload.available);
|
|
374
|
+
* });
|
|
375
|
+
*
|
|
376
|
+
* // Send the request
|
|
377
|
+
* NativeBridge.checkIAPAvailability();
|
|
378
|
+
*/
|
|
379
|
+
static checkIAPAvailability(): void;
|
|
380
|
+
/**
|
|
381
|
+
* Requests notification permission from the native app
|
|
382
|
+
* The native app will respond with PUSH_PERMISSION_GRANTED or PUSH_PERMISSION_DENIED
|
|
383
|
+
*
|
|
384
|
+
* @example
|
|
385
|
+
* // Listen for the response
|
|
386
|
+
* NativeBridge.on("PUSH_PERMISSION_GRANTED", () => {
|
|
387
|
+
* console.log("Permission granted");
|
|
388
|
+
* });
|
|
389
|
+
*
|
|
390
|
+
* NativeBridge.on("PUSH_PERMISSION_DENIED", () => {
|
|
391
|
+
* console.log("Permission denied");
|
|
392
|
+
* });
|
|
393
|
+
*
|
|
394
|
+
* // Send the request
|
|
395
|
+
* NativeBridge.requestNotificationPermission();
|
|
396
|
+
*/
|
|
397
|
+
static requestNotificationPermission(): void;
|
|
398
|
+
/**
|
|
399
|
+
* Requests available products for a specific game
|
|
400
|
+
* The native app will respond with PRODUCTS_RESULT containing product details
|
|
401
|
+
*
|
|
402
|
+
* @param gameId - The game ID to fetch products for
|
|
403
|
+
*
|
|
404
|
+
* @example
|
|
405
|
+
* // Listen for the response
|
|
406
|
+
* NativeBridge.on("PRODUCTS_RESULT", (payload) => {
|
|
407
|
+
* console.log("Products:", payload.products);
|
|
408
|
+
* });
|
|
409
|
+
*
|
|
410
|
+
* // Send the request
|
|
411
|
+
* NativeBridge.getProducts(123);
|
|
412
|
+
*/
|
|
413
|
+
static getProducts(gameId: number): void;
|
|
414
|
+
/**
|
|
415
|
+
* Initiates a purchase for a specific product
|
|
416
|
+
* The native app will respond with PURCHASE_COMPLETE or PURCHASE_ERROR
|
|
417
|
+
*
|
|
418
|
+
* @param productId - The product ID to purchase
|
|
419
|
+
* @param userId - The user ID making the purchase
|
|
420
|
+
*
|
|
421
|
+
* @example
|
|
422
|
+
* // Listen for responses
|
|
423
|
+
* NativeBridge.on("PURCHASE_COMPLETE", (payload) => {
|
|
424
|
+
* console.log("Purchase successful:", payload.productId);
|
|
425
|
+
* });
|
|
426
|
+
*
|
|
427
|
+
* NativeBridge.on("PURCHASE_ERROR", (payload) => {
|
|
428
|
+
* console.error("Purchase failed:", payload.error);
|
|
429
|
+
* });
|
|
430
|
+
*
|
|
431
|
+
* // Initiate purchase
|
|
432
|
+
* NativeBridge.purchase("product_123", "user_456");
|
|
433
|
+
*/
|
|
434
|
+
static purchase(productId: string, userId: string): void;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* Generates a random UUID (v4) using the uuid library
|
|
439
|
+
* @returns A string containing a randomly generated UUID
|
|
440
|
+
*/
|
|
441
|
+
declare function generateUUID(): string;
|
|
442
|
+
|
|
443
|
+
export { HyveClient, type Inventory, type InventoryItem, Logger, NativeBridge, type NativeMessage, type NativeMessageHandler, NativeMessageType, type TelemetryAdditionalData, type TelemetryConfig, type TelemetryEvent, generateUUID, handleVerifyMessage, isDomainAllowed, logger, parseUrlParams, validateSignature, verifyAuthentication, verifyHyveToken };
|