@hyve-sdk/js 1.3.2-canary.1 → 1.3.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/dist/index.js +57 -8
- package/dist/index.mjs +57 -8
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -560,6 +560,51 @@ var NativeBridge = class {
|
|
|
560
560
|
}
|
|
561
561
|
};
|
|
562
562
|
|
|
563
|
+
// src/utils/jwt.ts
|
|
564
|
+
function decodeJwt(token) {
|
|
565
|
+
try {
|
|
566
|
+
const parts = token.split(".");
|
|
567
|
+
if (parts.length !== 3) {
|
|
568
|
+
logger.warn("Invalid JWT format - expected 3 parts");
|
|
569
|
+
return null;
|
|
570
|
+
}
|
|
571
|
+
const payload = parts[1];
|
|
572
|
+
const base64 = payload.replace(/-/g, "+").replace(/_/g, "/");
|
|
573
|
+
const jsonPayload = atob(base64);
|
|
574
|
+
const decoded = JSON.parse(jsonPayload);
|
|
575
|
+
logger.debug("JWT decoded successfully:", decoded);
|
|
576
|
+
return decoded;
|
|
577
|
+
} catch (error) {
|
|
578
|
+
logger.error("Failed to decode JWT:", error);
|
|
579
|
+
return null;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
function extractUserIdFromJwt(token) {
|
|
583
|
+
const payload = decodeJwt(token);
|
|
584
|
+
if (!payload) {
|
|
585
|
+
return null;
|
|
586
|
+
}
|
|
587
|
+
const userId = payload.sub || payload.user_id?.toString();
|
|
588
|
+
if (userId) {
|
|
589
|
+
logger.info("Extracted user ID from JWT:", userId);
|
|
590
|
+
return userId;
|
|
591
|
+
}
|
|
592
|
+
logger.warn("No user ID found in JWT payload");
|
|
593
|
+
return null;
|
|
594
|
+
}
|
|
595
|
+
function extractGameIdFromJwt(token) {
|
|
596
|
+
const payload = decodeJwt(token);
|
|
597
|
+
if (!payload) {
|
|
598
|
+
return null;
|
|
599
|
+
}
|
|
600
|
+
const gameId = payload.game_id;
|
|
601
|
+
if (typeof gameId === "number") {
|
|
602
|
+
logger.info("Extracted game ID from JWT:", gameId);
|
|
603
|
+
return gameId;
|
|
604
|
+
}
|
|
605
|
+
return null;
|
|
606
|
+
}
|
|
607
|
+
|
|
563
608
|
// src/utils/index.ts
|
|
564
609
|
function generateUUID() {
|
|
565
610
|
return (0, import_uuid.v4)();
|
|
@@ -797,14 +842,18 @@ var HyveClient = class {
|
|
|
797
842
|
if (params.hyveAccess) {
|
|
798
843
|
this.jwtToken = params.hyveAccess;
|
|
799
844
|
logger.info("JWT token extracted from hyve-access parameter");
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
845
|
+
const userId = extractUserIdFromJwt(this.jwtToken);
|
|
846
|
+
if (userId) {
|
|
847
|
+
this.userId = userId;
|
|
848
|
+
logger.info("User ID extracted from JWT:", userId);
|
|
849
|
+
}
|
|
850
|
+
if (!this.gameId) {
|
|
851
|
+
const gameIdFromJwt = extractGameIdFromJwt(this.jwtToken);
|
|
852
|
+
if (gameIdFromJwt !== null) {
|
|
853
|
+
this.gameId = gameIdFromJwt.toString();
|
|
854
|
+
logger.info("Game ID extracted from JWT:", gameIdFromJwt);
|
|
855
|
+
}
|
|
856
|
+
}
|
|
808
857
|
}
|
|
809
858
|
if (params.gameId) {
|
|
810
859
|
this.gameId = params.gameId;
|
package/dist/index.mjs
CHANGED
|
@@ -520,6 +520,51 @@ var NativeBridge = class {
|
|
|
520
520
|
}
|
|
521
521
|
};
|
|
522
522
|
|
|
523
|
+
// src/utils/jwt.ts
|
|
524
|
+
function decodeJwt(token) {
|
|
525
|
+
try {
|
|
526
|
+
const parts = token.split(".");
|
|
527
|
+
if (parts.length !== 3) {
|
|
528
|
+
logger.warn("Invalid JWT format - expected 3 parts");
|
|
529
|
+
return null;
|
|
530
|
+
}
|
|
531
|
+
const payload = parts[1];
|
|
532
|
+
const base64 = payload.replace(/-/g, "+").replace(/_/g, "/");
|
|
533
|
+
const jsonPayload = atob(base64);
|
|
534
|
+
const decoded = JSON.parse(jsonPayload);
|
|
535
|
+
logger.debug("JWT decoded successfully:", decoded);
|
|
536
|
+
return decoded;
|
|
537
|
+
} catch (error) {
|
|
538
|
+
logger.error("Failed to decode JWT:", error);
|
|
539
|
+
return null;
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
function extractUserIdFromJwt(token) {
|
|
543
|
+
const payload = decodeJwt(token);
|
|
544
|
+
if (!payload) {
|
|
545
|
+
return null;
|
|
546
|
+
}
|
|
547
|
+
const userId = payload.sub || payload.user_id?.toString();
|
|
548
|
+
if (userId) {
|
|
549
|
+
logger.info("Extracted user ID from JWT:", userId);
|
|
550
|
+
return userId;
|
|
551
|
+
}
|
|
552
|
+
logger.warn("No user ID found in JWT payload");
|
|
553
|
+
return null;
|
|
554
|
+
}
|
|
555
|
+
function extractGameIdFromJwt(token) {
|
|
556
|
+
const payload = decodeJwt(token);
|
|
557
|
+
if (!payload) {
|
|
558
|
+
return null;
|
|
559
|
+
}
|
|
560
|
+
const gameId = payload.game_id;
|
|
561
|
+
if (typeof gameId === "number") {
|
|
562
|
+
logger.info("Extracted game ID from JWT:", gameId);
|
|
563
|
+
return gameId;
|
|
564
|
+
}
|
|
565
|
+
return null;
|
|
566
|
+
}
|
|
567
|
+
|
|
523
568
|
// src/utils/index.ts
|
|
524
569
|
function generateUUID() {
|
|
525
570
|
return uuidv4();
|
|
@@ -757,14 +802,18 @@ var HyveClient = class {
|
|
|
757
802
|
if (params.hyveAccess) {
|
|
758
803
|
this.jwtToken = params.hyveAccess;
|
|
759
804
|
logger.info("JWT token extracted from hyve-access parameter");
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
805
|
+
const userId = extractUserIdFromJwt(this.jwtToken);
|
|
806
|
+
if (userId) {
|
|
807
|
+
this.userId = userId;
|
|
808
|
+
logger.info("User ID extracted from JWT:", userId);
|
|
809
|
+
}
|
|
810
|
+
if (!this.gameId) {
|
|
811
|
+
const gameIdFromJwt = extractGameIdFromJwt(this.jwtToken);
|
|
812
|
+
if (gameIdFromJwt !== null) {
|
|
813
|
+
this.gameId = gameIdFromJwt.toString();
|
|
814
|
+
logger.info("Game ID extracted from JWT:", gameIdFromJwt);
|
|
815
|
+
}
|
|
816
|
+
}
|
|
768
817
|
}
|
|
769
818
|
if (params.gameId) {
|
|
770
819
|
this.gameId = params.gameId;
|