@hyve-sdk/js 1.1.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/dist/index.d.ts CHANGED
@@ -2,33 +2,39 @@
2
2
  * Telemetry configuration options
3
3
  */
4
4
  interface TelemetryConfig {
5
- /** API key for telemetry service */
6
- apiKey?: string;
7
5
  /** Environment: true for dev, false for prod. Defaults to true (dev) */
8
6
  isDev?: boolean;
9
7
  /** Base API URL for all API calls (telemetry and external). Can be set via env. If not provided, defaults based on isDev */
10
8
  apiBaseUrl?: string;
11
9
  }
12
10
  /**
13
- * Telemetry event data structure
11
+ * Telemetry event data structure for user-level events (JWT authenticated)
12
+ * Matches backend SendTelemetryRequest model
13
+ * Note: hyve_user_id is extracted from JWT by backend, not sent in request
14
14
  */
15
15
  interface TelemetryEvent {
16
- /** Unique session identifier */
16
+ /** Game identifier (required) */
17
+ game_id: string;
18
+ /** Unique session identifier (required) */
17
19
  session_id: string;
18
- /** Hyve user identifier (address) */
19
- hyve_user_id: string;
20
- /** Location where the event occurred */
20
+ /** Platform/user identifier (optional) */
21
+ platform_id?: string | null;
22
+ /** Location where the event occurred (required) */
21
23
  event_location: string;
22
- /** Main category of the event */
24
+ /** Main category of the event (required) */
23
25
  event_category: string;
24
- /** Primary action taken */
26
+ /** Sub-category for more granular classification (optional) */
27
+ event_sub_category?: string | null;
28
+ /** Primary action taken (required) */
25
29
  event_action: string;
26
- /** Sub-category for more granular classification (null if not provided) */
27
- event_sub_category: string | null;
28
- /** Sub-action for detailed tracking (null if not provided) */
29
- event_sub_action: string | null;
30
- /** Additional data as JSON string (null if not provided) */
31
- event_details: string | null;
30
+ /** Sub-action for detailed tracking (optional) */
31
+ event_sub_action?: string | null;
32
+ /** Event details as JSON string or object (optional) */
33
+ event_details?: Record<string, any> | string | null;
34
+ /** Mapping details as JSON string or object (optional) */
35
+ mapping_details?: Record<string, any> | string | null;
36
+ /** Custom data as JSON string or object (optional) */
37
+ custom_data?: Record<string, any> | string | null;
32
38
  }
33
39
  /**
34
40
  * Additional telemetry data that can be passed with events
@@ -67,6 +73,7 @@ declare class HyveClient {
67
73
  private sessionId;
68
74
  private userId;
69
75
  private jwtToken;
76
+ private gameId;
70
77
  /**
71
78
  * Creates a new HyveClient instance
72
79
  * @param config Optional telemetry configuration
@@ -79,17 +86,19 @@ declare class HyveClient {
79
86
  */
80
87
  authenticateFromUrl(urlParams?: URLSearchParams | string): Promise<boolean>;
81
88
  /**
82
- * Sends a telemetry event
89
+ * Sends a user-level telemetry event using JWT authentication
90
+ * Requires JWT token, authenticated user, and game ID from URL parameters
83
91
  * @param eventLocation Location where the event occurred
84
92
  * @param eventCategory Main category of the event
85
93
  * @param eventAction Primary action taken
86
94
  * @param eventSubCategory Optional sub-category
87
95
  * @param eventSubAction Optional sub-action
88
- * @param eventDetails Optional event details
89
- * @param additionalData Optional additional data
96
+ * @param eventDetails Optional event details (object or JSON string)
97
+ * @param customData Optional custom data (object or JSON string)
98
+ * @param platformId Optional platform identifier
90
99
  * @returns Promise resolving to boolean indicating success
91
100
  */
92
- sendTelemetry(eventLocation: string, eventCategory: string, eventAction: string, eventSubCategory?: string | null, eventSubAction?: string | null, eventDetails?: string | null, additionalData?: TelemetryAdditionalData | null): Promise<boolean>;
101
+ sendTelemetry(eventLocation: string, eventCategory: string, eventAction: string, eventSubCategory?: string | null, eventSubAction?: string | null, eventDetails?: Record<string, any> | string | null, customData?: Record<string, any> | null, platformId?: string | null): Promise<boolean>;
93
102
  /**
94
103
  * Makes an authenticated API call using the JWT token
95
104
  * @param endpoint API endpoint path (will be appended to base URL)
@@ -128,6 +137,11 @@ declare class HyveClient {
128
137
  * @returns Current JWT token or null if not available
129
138
  */
130
139
  getJwtToken(): string | null;
140
+ /**
141
+ * Gets the current game ID
142
+ * @returns Current game ID or null if not available
143
+ */
144
+ getGameId(): string | null;
131
145
  /**
132
146
  * Gets the API base URL
133
147
  * @returns API base URL
@@ -153,6 +167,53 @@ declare class HyveClient {
153
167
  reset(): void;
154
168
  }
155
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
+
156
217
  /**
157
218
  * Parses URL search parameters and returns commonly used values
158
219
  * @param searchParams URLSearchParams object or string
@@ -165,6 +226,7 @@ declare function parseUrlParams(searchParams: URLSearchParams | string): {
165
226
  hyveToken: string;
166
227
  platform: string;
167
228
  hyveAccess: string;
229
+ gameId: string;
168
230
  };
169
231
  /**
170
232
  * Validates an EVM signature against a message and user ID
@@ -203,11 +265,6 @@ declare function verifyAuthentication(params: {
203
265
  method: "modern" | "legacy" | "none";
204
266
  error?: string;
205
267
  };
206
- /**
207
- * Generates a random UUID (v4) using the uuid library
208
- * @returns A string containing a randomly generated UUID
209
- */
210
- declare function generateUUID(): string;
211
268
  /**
212
269
  * Checks if the current domain is in the list of allowed domains
213
270
  * @param allowedDomains Array of allowed domains or a single domain string
@@ -215,4 +272,172 @@ declare function generateUUID(): string;
215
272
  */
216
273
  declare function isDomainAllowed(allowedDomains?: string | string[], hostname?: string): boolean;
217
274
 
218
- export { HyveClient, type Inventory, type InventoryItem, type TelemetryAdditionalData, type TelemetryConfig, type TelemetryEvent, generateUUID, handleVerifyMessage, isDomainAllowed, parseUrlParams, validateSignature, verifyAuthentication, verifyHyveToken };
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 };