@hyve-sdk/js 1.1.2 → 1.2.2

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 CHANGED
@@ -34,17 +34,18 @@ import { HyveClient } from "@hyve-sdk/js";
34
34
 
35
35
  // Initialize with optional configuration
36
36
  const client = new HyveClient({
37
- apiKey: 'your-api-key', // For telemetry
38
37
  isDev: true, // Development mode (default: true)
39
38
  apiBaseUrl: 'https://...' // Optional custom API URL
40
39
  });
41
40
 
42
41
  // Authenticate from URL parameters
42
+ // Extracts: hyve-token/signature, hyve-access (JWT), game-id
43
43
  const authenticated = await client.authenticateFromUrl();
44
44
  if (authenticated) {
45
45
  console.log('User ID:', client.getUserId());
46
46
  console.log('Session ID:', client.getSessionId());
47
47
  console.log('Has JWT:', client.hasJwtToken());
48
+ console.log('Game ID:', client.getGameId());
48
49
  }
49
50
  ```
50
51
 
@@ -61,10 +62,11 @@ const params = parseUrlParams(window.location.search);
61
62
  // {
62
63
  // signature: string,
63
64
  // message: string,
64
- // userId: string,
65
65
  // gameStartTab: string,
66
66
  // hyveToken: string,
67
- // platform: string
67
+ // platform: string,
68
+ // hyveAccess: string, // JWT token
69
+ // gameId: string // Game identifier
68
70
  // }
69
71
  ```
70
72
 
@@ -146,46 +148,62 @@ const id = generateUUID();
146
148
  ## Telemetry & Analytics
147
149
 
148
150
  ### Send Telemetry Events
149
- Track user actions and game events:
151
+ Track user actions and game events using JWT authentication:
150
152
 
151
153
  ```typescript
152
- // Send a custom telemetry event
154
+ // Send a user-level telemetry event
155
+ // Game ID is automatically extracted from 'game-id' URL parameter
153
156
  await client.sendTelemetry(
154
157
  'game', // Event location
155
158
  'player', // Event category
156
159
  'action', // Event action
157
160
  'combat', // Event sub-category (optional)
158
161
  'attack', // Event sub-action (optional)
159
- null, // Event details string (optional)
160
- { // Additional data (optional)
162
+ { // Event details - auto-stringified (optional)
163
+ button: 'attack-btn',
164
+ screenPosition: { x: 100, y: 200 }
165
+ },
166
+ { // Custom data - auto-stringified (optional)
161
167
  damage: 100,
162
168
  targetId: 'enemy-123',
163
- weaponType: 'sword'
164
- }
169
+ weaponType: 'sword',
170
+ level: 3
171
+ },
172
+ 'web-chrome' // Platform ID (optional)
165
173
  );
166
174
  ```
167
175
 
168
- **Configuration:**
169
- - Requires `apiKey` in client configuration
170
- - Automatically includes `session_id` and `user_id`
171
- - Additional data is JSON-stringified into `event_details`
172
- - Supports anonymous telemetry (without authentication)
176
+ **Requirements:**
177
+ - Requires JWT token (from `hyve-access` URL parameter)
178
+ - Requires authenticated user
179
+ - Requires game ID (from `game-id` URL parameter)
180
+ - User ID is automatically extracted from JWT (cannot be spoofed)
181
+
182
+ **URL Parameters Expected:**
183
+ - `hyve-access` - JWT authentication token
184
+ - `game-id` - Game identifier (associates all telemetry with this game)
185
+ - `hyve-token` or `signature`+`message` - For user authentication
186
+
187
+ **Features:**
188
+ - Automatically includes `session_id` and `game_id` from client
189
+ - Objects in `event_details` and `custom_data` are auto-stringified to JSON
190
+ - All events tied to authenticated user identity
173
191
 
174
192
  ## API Integration
175
193
 
176
194
  ### JWT Authentication
177
- The SDK supports JWT tokens passed via URL parameter `hyve-access`:
195
+ The SDK supports JWT tokens and game IDs passed via URL parameters:
178
196
 
179
197
  ```typescript
180
- // URL: https://game.com?hyve-access=your-jwt-token
198
+ // URL: https://game.com?hyve-access=your-jwt-token&game-id=my-game
181
199
 
182
- // Authenticate extracts JWT automatically
200
+ // Authenticate extracts JWT and game ID automatically
183
201
  await client.authenticateFromUrl();
184
202
 
185
- // Check JWT availability
203
+ // Check availability
186
204
  if (client.hasJwtToken()) {
187
- const token = client.getJwtToken();
188
- console.log('JWT token available');
205
+ console.log('JWT token:', client.getJwtToken());
206
+ console.log('Game ID:', client.getGameId());
189
207
  }
190
208
  ```
191
209
 
@@ -267,9 +285,10 @@ if (item.metadata) {
267
285
  ## Client Methods Reference
268
286
 
269
287
  ### Authentication
270
- - `authenticateFromUrl(urlParams?)` - Authenticate from URL parameters
288
+ - `authenticateFromUrl(urlParams?)` - Authenticate from URL parameters (extracts JWT, game ID, user auth)
271
289
  - `getUserId()` - Get authenticated user ID (address)
272
290
  - `getSessionId()` - Get unique session ID
291
+ - `getGameId()` - Get game ID from URL parameters
273
292
  - `isUserAuthenticated()` - Check if user is authenticated
274
293
  - `hasJwtToken()` - Check if JWT token is available
275
294
  - `getJwtToken()` - Get JWT token string
@@ -282,7 +301,7 @@ if (item.metadata) {
282
301
  - `getInventoryItem(itemId)` - Get specific inventory item
283
302
 
284
303
  ### Telemetry
285
- - `sendTelemetry(location, category, action, subCategory?, subAction?, details?, additionalData?)` - Send analytics event
304
+ - `sendTelemetry(location, category, action, subCategory?, subAction?, details?, customData?, platformId?)` - Send JWT-authenticated analytics event (uses game ID from URL)
286
305
  - `updateTelemetryConfig(config)` - Update telemetry settings
287
306
 
288
307
  ### Configuration
package/dist/index.d.mts 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
@@ -165,6 +179,7 @@ declare function parseUrlParams(searchParams: URLSearchParams | string): {
165
179
  hyveToken: string;
166
180
  platform: string;
167
181
  hyveAccess: string;
182
+ gameId: string;
168
183
  };
169
184
  /**
170
185
  * Validates an EVM signature against a message and user ID
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
@@ -165,6 +179,7 @@ declare function parseUrlParams(searchParams: URLSearchParams | string): {
165
179
  hyveToken: string;
166
180
  platform: string;
167
181
  hyveAccess: string;
182
+ gameId: string;
168
183
  };
169
184
  /**
170
185
  * Validates an EVM signature against a message and user ID
package/dist/index.js CHANGED
@@ -42,7 +42,8 @@ function parseUrlParams(searchParams) {
42
42
  gameStartTab: params.get("game_start_tab") || "",
43
43
  hyveToken: params.get("hyve-token") || "",
44
44
  platform: params.get("platform") || "",
45
- hyveAccess: params.get("hyve-access") || ""
45
+ hyveAccess: params.get("hyve-access") || "",
46
+ gameId: params.get("game-id") || ""
46
47
  };
47
48
  }
48
49
  function validateSignature(signature, message) {
@@ -191,6 +192,7 @@ var HyveClient = class {
191
192
  sessionId;
192
193
  userId = null;
193
194
  jwtToken = null;
195
+ gameId = null;
194
196
  /**
195
197
  * Creates a new HyveClient instance
196
198
  * @param config Optional telemetry configuration
@@ -223,6 +225,14 @@ var HyveClient = class {
223
225
  this.jwtToken = params.hyveAccess;
224
226
  console.log("[Hyve SDK] JWT token extracted from hyve-access parameter");
225
227
  }
228
+ if (params.gameId) {
229
+ this.gameId = params.gameId;
230
+ console.log("[Hyve SDK] Game ID extracted from game-id parameter:", this.gameId);
231
+ }
232
+ if (this.jwtToken) {
233
+ console.log("[Hyve SDK] Authentication successful via JWT");
234
+ return true;
235
+ }
226
236
  const authResult = verifyAuthentication({
227
237
  hyveToken: params.hyveToken,
228
238
  signature: params.signature,
@@ -245,48 +255,51 @@ var HyveClient = class {
245
255
  }
246
256
  }
247
257
  /**
248
- * Sends a telemetry event
258
+ * Sends a user-level telemetry event using JWT authentication
259
+ * Requires JWT token, authenticated user, and game ID from URL parameters
249
260
  * @param eventLocation Location where the event occurred
250
261
  * @param eventCategory Main category of the event
251
262
  * @param eventAction Primary action taken
252
263
  * @param eventSubCategory Optional sub-category
253
264
  * @param eventSubAction Optional sub-action
254
- * @param eventDetails Optional event details
255
- * @param additionalData Optional additional data
265
+ * @param eventDetails Optional event details (object or JSON string)
266
+ * @param customData Optional custom data (object or JSON string)
267
+ * @param platformId Optional platform identifier
256
268
  * @returns Promise resolving to boolean indicating success
257
269
  */
258
- async sendTelemetry(eventLocation, eventCategory, eventAction, eventSubCategory, eventSubAction, eventDetails, additionalData) {
259
- if (!this.telemetryConfig.apiKey) {
260
- console.error("[Hyve Telemetry] API key not configured");
270
+ async sendTelemetry(eventLocation, eventCategory, eventAction, eventSubCategory, eventSubAction, eventDetails, customData, platformId) {
271
+ if (!this.jwtToken) {
272
+ console.error("[Hyve Telemetry] JWT token required. Call authenticateFromUrl first.");
261
273
  return false;
262
274
  }
263
- if (!this.userId) {
264
- console.warn("[Hyve Telemetry] No user ID - sending anonymous telemetry");
275
+ if (!this.gameId) {
276
+ console.error("[Hyve Telemetry] Game ID required. Ensure game-id URL parameter is set.");
277
+ return false;
265
278
  }
266
279
  try {
267
- let finalEventDetails = null;
268
- if (additionalData && Object.keys(additionalData).length > 0) {
269
- finalEventDetails = JSON.stringify(additionalData);
270
- } else if (eventDetails) {
271
- finalEventDetails = eventDetails;
272
- }
280
+ const toJsonString = (data) => {
281
+ if (!data) return null;
282
+ return typeof data === "string" ? data : JSON.stringify(data);
283
+ };
273
284
  const telemetryEvent = {
285
+ game_id: this.gameId,
274
286
  session_id: this.sessionId,
275
- hyve_user_id: this.userId || "anonymous",
287
+ platform_id: platformId || null,
276
288
  event_location: eventLocation,
277
289
  event_category: eventCategory,
278
290
  event_action: eventAction,
279
291
  event_sub_category: eventSubCategory || null,
280
292
  event_sub_action: eventSubAction || null,
281
- event_details: finalEventDetails
293
+ event_details: toJsonString(eventDetails),
294
+ custom_data: toJsonString(customData)
282
295
  };
283
- console.log("[Hyve Telemetry] Sending event:", telemetryEvent);
284
- const telemetryUrl = `${this.apiBaseUrl}/api/v1/partners/analytics/events`;
296
+ console.log("[Hyve Telemetry] Sending user-level event:", telemetryEvent);
297
+ const telemetryUrl = `${this.apiBaseUrl}/api/v1/telemetry/send`;
285
298
  const response = await fetch(telemetryUrl, {
286
299
  method: "POST",
287
300
  headers: {
288
301
  "Content-Type": "application/json",
289
- "X-API-KEY": this.telemetryConfig.apiKey
302
+ "Authorization": `Bearer ${this.jwtToken}`
290
303
  },
291
304
  body: JSON.stringify(telemetryEvent)
292
305
  });
@@ -386,6 +399,13 @@ var HyveClient = class {
386
399
  getJwtToken() {
387
400
  return this.jwtToken;
388
401
  }
402
+ /**
403
+ * Gets the current game ID
404
+ * @returns Current game ID or null if not available
405
+ */
406
+ getGameId() {
407
+ return this.gameId;
408
+ }
389
409
  /**
390
410
  * Gets the API base URL
391
411
  * @returns API base URL
@@ -413,6 +433,7 @@ var HyveClient = class {
413
433
  logout() {
414
434
  this.userId = null;
415
435
  this.jwtToken = null;
436
+ this.gameId = null;
416
437
  console.log("[Hyve SDK] User logged out");
417
438
  }
418
439
  /**
package/dist/index.mjs CHANGED
@@ -9,7 +9,8 @@ function parseUrlParams(searchParams) {
9
9
  gameStartTab: params.get("game_start_tab") || "",
10
10
  hyveToken: params.get("hyve-token") || "",
11
11
  platform: params.get("platform") || "",
12
- hyveAccess: params.get("hyve-access") || ""
12
+ hyveAccess: params.get("hyve-access") || "",
13
+ gameId: params.get("game-id") || ""
13
14
  };
14
15
  }
15
16
  function validateSignature(signature, message) {
@@ -158,6 +159,7 @@ var HyveClient = class {
158
159
  sessionId;
159
160
  userId = null;
160
161
  jwtToken = null;
162
+ gameId = null;
161
163
  /**
162
164
  * Creates a new HyveClient instance
163
165
  * @param config Optional telemetry configuration
@@ -190,6 +192,14 @@ var HyveClient = class {
190
192
  this.jwtToken = params.hyveAccess;
191
193
  console.log("[Hyve SDK] JWT token extracted from hyve-access parameter");
192
194
  }
195
+ if (params.gameId) {
196
+ this.gameId = params.gameId;
197
+ console.log("[Hyve SDK] Game ID extracted from game-id parameter:", this.gameId);
198
+ }
199
+ if (this.jwtToken) {
200
+ console.log("[Hyve SDK] Authentication successful via JWT");
201
+ return true;
202
+ }
193
203
  const authResult = verifyAuthentication({
194
204
  hyveToken: params.hyveToken,
195
205
  signature: params.signature,
@@ -212,48 +222,51 @@ var HyveClient = class {
212
222
  }
213
223
  }
214
224
  /**
215
- * Sends a telemetry event
225
+ * Sends a user-level telemetry event using JWT authentication
226
+ * Requires JWT token, authenticated user, and game ID from URL parameters
216
227
  * @param eventLocation Location where the event occurred
217
228
  * @param eventCategory Main category of the event
218
229
  * @param eventAction Primary action taken
219
230
  * @param eventSubCategory Optional sub-category
220
231
  * @param eventSubAction Optional sub-action
221
- * @param eventDetails Optional event details
222
- * @param additionalData Optional additional data
232
+ * @param eventDetails Optional event details (object or JSON string)
233
+ * @param customData Optional custom data (object or JSON string)
234
+ * @param platformId Optional platform identifier
223
235
  * @returns Promise resolving to boolean indicating success
224
236
  */
225
- async sendTelemetry(eventLocation, eventCategory, eventAction, eventSubCategory, eventSubAction, eventDetails, additionalData) {
226
- if (!this.telemetryConfig.apiKey) {
227
- console.error("[Hyve Telemetry] API key not configured");
237
+ async sendTelemetry(eventLocation, eventCategory, eventAction, eventSubCategory, eventSubAction, eventDetails, customData, platformId) {
238
+ if (!this.jwtToken) {
239
+ console.error("[Hyve Telemetry] JWT token required. Call authenticateFromUrl first.");
228
240
  return false;
229
241
  }
230
- if (!this.userId) {
231
- console.warn("[Hyve Telemetry] No user ID - sending anonymous telemetry");
242
+ if (!this.gameId) {
243
+ console.error("[Hyve Telemetry] Game ID required. Ensure game-id URL parameter is set.");
244
+ return false;
232
245
  }
233
246
  try {
234
- let finalEventDetails = null;
235
- if (additionalData && Object.keys(additionalData).length > 0) {
236
- finalEventDetails = JSON.stringify(additionalData);
237
- } else if (eventDetails) {
238
- finalEventDetails = eventDetails;
239
- }
247
+ const toJsonString = (data) => {
248
+ if (!data) return null;
249
+ return typeof data === "string" ? data : JSON.stringify(data);
250
+ };
240
251
  const telemetryEvent = {
252
+ game_id: this.gameId,
241
253
  session_id: this.sessionId,
242
- hyve_user_id: this.userId || "anonymous",
254
+ platform_id: platformId || null,
243
255
  event_location: eventLocation,
244
256
  event_category: eventCategory,
245
257
  event_action: eventAction,
246
258
  event_sub_category: eventSubCategory || null,
247
259
  event_sub_action: eventSubAction || null,
248
- event_details: finalEventDetails
260
+ event_details: toJsonString(eventDetails),
261
+ custom_data: toJsonString(customData)
249
262
  };
250
- console.log("[Hyve Telemetry] Sending event:", telemetryEvent);
251
- const telemetryUrl = `${this.apiBaseUrl}/api/v1/partners/analytics/events`;
263
+ console.log("[Hyve Telemetry] Sending user-level event:", telemetryEvent);
264
+ const telemetryUrl = `${this.apiBaseUrl}/api/v1/telemetry/send`;
252
265
  const response = await fetch(telemetryUrl, {
253
266
  method: "POST",
254
267
  headers: {
255
268
  "Content-Type": "application/json",
256
- "X-API-KEY": this.telemetryConfig.apiKey
269
+ "Authorization": `Bearer ${this.jwtToken}`
257
270
  },
258
271
  body: JSON.stringify(telemetryEvent)
259
272
  });
@@ -353,6 +366,13 @@ var HyveClient = class {
353
366
  getJwtToken() {
354
367
  return this.jwtToken;
355
368
  }
369
+ /**
370
+ * Gets the current game ID
371
+ * @returns Current game ID or null if not available
372
+ */
373
+ getGameId() {
374
+ return this.gameId;
375
+ }
356
376
  /**
357
377
  * Gets the API base URL
358
378
  * @returns API base URL
@@ -380,6 +400,7 @@ var HyveClient = class {
380
400
  logout() {
381
401
  this.userId = null;
382
402
  this.jwtToken = null;
403
+ this.gameId = null;
383
404
  console.log("[Hyve SDK] User logged out");
384
405
  }
385
406
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyve-sdk/js",
3
- "version": "1.1.2",
3
+ "version": "1.2.2",
4
4
  "description": "Hyve SDK - TypeScript wrapper for Hyve game server integration",
5
5
  "private": false,
6
6
  "publishConfig": {
@@ -44,14 +44,14 @@
44
44
  "@types/uuid": "^10.0.0",
45
45
  "tsup": "^8.4.0",
46
46
  "typescript": "^5.3.3",
47
- "@repo/eslint-config": "0.0.0",
48
- "@repo/typescript-config": "0.0.0"
47
+ "@repo/typescript-config": "0.0.0",
48
+ "@repo/eslint-config": "0.0.0"
49
49
  },
50
50
  "scripts": {
51
51
  "lint": "eslint . --max-warnings 0",
52
52
  "check-types": "tsc --noEmit",
53
53
  "build": "tsup src/index.ts --format cjs,esm --dts --clean",
54
- "publish:npm": "pnpm publish --access public --no-git-checks",
54
+ "publish:npm": "pnpm publish --access public",
55
55
  "publish:dry-run": "pnpm publish --dry-run --access public --no-git-checks"
56
56
  }
57
57
  }