@hyve-sdk/js 1.4.1 → 1.5.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.mts CHANGED
@@ -443,6 +443,7 @@ declare class HyveClient {
443
443
  private jwtToken;
444
444
  private gameId;
445
445
  private adsService;
446
+ private playgamaService;
446
447
  private billingService;
447
448
  private billingConfig;
448
449
  private billingCallbacks;
@@ -674,6 +675,54 @@ declare class HyveClient {
674
675
  onBillingLog(callback: (level: "info" | "warn" | "error", message: string, data?: any) => void): void;
675
676
  }
676
677
 
678
+ /**
679
+ * Playgama Bridge integration service
680
+ *
681
+ * Loads and initializes the Playgama Bridge SDK when running on a Playgama domain.
682
+ * The bridge SDK is loaded from CDN and exposes a global `window.bridge` object.
683
+ *
684
+ * Detection: Playgama games receive a `platform_id=playgama` URL parameter when
685
+ * embedded on the platform.
686
+ *
687
+ * @packageDocumentation
688
+ */
689
+
690
+ interface PlaygamaBridgeAdvertisement {
691
+ interstitialState: string;
692
+ rewardedState: string;
693
+ showInterstitial(placement?: string): void;
694
+ showRewarded(placement?: string): void;
695
+ on(event: string, callback: (state: string) => void): void;
696
+ off(event: string, callback: (state: string) => void): void;
697
+ }
698
+ interface PlaygamaBridge {
699
+ initialize(): Promise<void>;
700
+ advertisement: PlaygamaBridgeAdvertisement;
701
+ }
702
+ declare global {
703
+ interface Window {
704
+ bridge?: PlaygamaBridge;
705
+ }
706
+ }
707
+ declare class PlaygamaService {
708
+ private initialized;
709
+ /**
710
+ * Detects if the game is running on the Playgama platform.
711
+ * Playgama injects a `platform_id=playgama` URL parameter into the game URL.
712
+ * Falls back to checking document.referrer for playgama.com.
713
+ */
714
+ static isPlaygamaDomain(): boolean;
715
+ /**
716
+ * Loads the Playgama Bridge script from CDN and initializes it.
717
+ * Safe to call multiple times - resolves immediately if already initialized.
718
+ */
719
+ initialize(): Promise<boolean>;
720
+ isInitialized(): boolean;
721
+ showInterstitial(): Promise<AdResult>;
722
+ showRewarded(): Promise<AdResult>;
723
+ private loadScript;
724
+ }
725
+
677
726
  /**
678
727
  * Storage adapter interface - supports cloud and local implementations
679
728
  */
@@ -988,4 +1037,4 @@ declare class NativeBridge {
988
1037
  */
989
1038
  declare function generateUUID(): string;
990
1039
 
991
- export { type AdConfig$1 as AdConfig, type AdResult, type AdType, AdsService, type BillingConfig, BillingPlatform, type BillingProduct, BillingService, CloudStorageAdapter, type DeleteGameDataResponse, type GameDataBatchItem, type GameDataItem, type GameDataValue, type GetGameDataBatchResponse, type GetGameDataResponse, HyveClient, type HyveClientConfig, type Inventory, type InventoryItem, LocalStorageAdapter, Logger, NativeBridge, type NativeMessage, type NativeMessageHandler, NativeMessageType, type PurchaseResult, type SaveGameDataResponse, type StorageAdapter, type TelemetryAdditionalData, type TelemetryConfig, type TelemetryEvent, generateUUID, handleVerifyMessage, isDomainAllowed, logger, parseUrlParams, validateSignature, verifyAuthentication, verifyHyveToken };
1040
+ export { type AdConfig$1 as AdConfig, type AdResult, type AdType, AdsService, type BillingConfig, BillingPlatform, type BillingProduct, BillingService, CloudStorageAdapter, type DeleteGameDataResponse, type GameDataBatchItem, type GameDataItem, type GameDataValue, type GetGameDataBatchResponse, type GetGameDataResponse, HyveClient, type HyveClientConfig, type Inventory, type InventoryItem, LocalStorageAdapter, Logger, NativeBridge, type NativeMessage, type NativeMessageHandler, NativeMessageType, PlaygamaService, type PurchaseResult, type SaveGameDataResponse, type StorageAdapter, type TelemetryAdditionalData, type TelemetryConfig, type TelemetryEvent, generateUUID, handleVerifyMessage, isDomainAllowed, logger, parseUrlParams, validateSignature, verifyAuthentication, verifyHyveToken };
package/dist/index.d.ts CHANGED
@@ -443,6 +443,7 @@ declare class HyveClient {
443
443
  private jwtToken;
444
444
  private gameId;
445
445
  private adsService;
446
+ private playgamaService;
446
447
  private billingService;
447
448
  private billingConfig;
448
449
  private billingCallbacks;
@@ -674,6 +675,54 @@ declare class HyveClient {
674
675
  onBillingLog(callback: (level: "info" | "warn" | "error", message: string, data?: any) => void): void;
675
676
  }
676
677
 
678
+ /**
679
+ * Playgama Bridge integration service
680
+ *
681
+ * Loads and initializes the Playgama Bridge SDK when running on a Playgama domain.
682
+ * The bridge SDK is loaded from CDN and exposes a global `window.bridge` object.
683
+ *
684
+ * Detection: Playgama games receive a `platform_id=playgama` URL parameter when
685
+ * embedded on the platform.
686
+ *
687
+ * @packageDocumentation
688
+ */
689
+
690
+ interface PlaygamaBridgeAdvertisement {
691
+ interstitialState: string;
692
+ rewardedState: string;
693
+ showInterstitial(placement?: string): void;
694
+ showRewarded(placement?: string): void;
695
+ on(event: string, callback: (state: string) => void): void;
696
+ off(event: string, callback: (state: string) => void): void;
697
+ }
698
+ interface PlaygamaBridge {
699
+ initialize(): Promise<void>;
700
+ advertisement: PlaygamaBridgeAdvertisement;
701
+ }
702
+ declare global {
703
+ interface Window {
704
+ bridge?: PlaygamaBridge;
705
+ }
706
+ }
707
+ declare class PlaygamaService {
708
+ private initialized;
709
+ /**
710
+ * Detects if the game is running on the Playgama platform.
711
+ * Playgama injects a `platform_id=playgama` URL parameter into the game URL.
712
+ * Falls back to checking document.referrer for playgama.com.
713
+ */
714
+ static isPlaygamaDomain(): boolean;
715
+ /**
716
+ * Loads the Playgama Bridge script from CDN and initializes it.
717
+ * Safe to call multiple times - resolves immediately if already initialized.
718
+ */
719
+ initialize(): Promise<boolean>;
720
+ isInitialized(): boolean;
721
+ showInterstitial(): Promise<AdResult>;
722
+ showRewarded(): Promise<AdResult>;
723
+ private loadScript;
724
+ }
725
+
677
726
  /**
678
727
  * Storage adapter interface - supports cloud and local implementations
679
728
  */
@@ -988,4 +1037,4 @@ declare class NativeBridge {
988
1037
  */
989
1038
  declare function generateUUID(): string;
990
1039
 
991
- export { type AdConfig$1 as AdConfig, type AdResult, type AdType, AdsService, type BillingConfig, BillingPlatform, type BillingProduct, BillingService, CloudStorageAdapter, type DeleteGameDataResponse, type GameDataBatchItem, type GameDataItem, type GameDataValue, type GetGameDataBatchResponse, type GetGameDataResponse, HyveClient, type HyveClientConfig, type Inventory, type InventoryItem, LocalStorageAdapter, Logger, NativeBridge, type NativeMessage, type NativeMessageHandler, NativeMessageType, type PurchaseResult, type SaveGameDataResponse, type StorageAdapter, type TelemetryAdditionalData, type TelemetryConfig, type TelemetryEvent, generateUUID, handleVerifyMessage, isDomainAllowed, logger, parseUrlParams, validateSignature, verifyAuthentication, verifyHyveToken };
1040
+ export { type AdConfig$1 as AdConfig, type AdResult, type AdType, AdsService, type BillingConfig, BillingPlatform, type BillingProduct, BillingService, CloudStorageAdapter, type DeleteGameDataResponse, type GameDataBatchItem, type GameDataItem, type GameDataValue, type GetGameDataBatchResponse, type GetGameDataResponse, HyveClient, type HyveClientConfig, type Inventory, type InventoryItem, LocalStorageAdapter, Logger, NativeBridge, type NativeMessage, type NativeMessageHandler, NativeMessageType, PlaygamaService, type PurchaseResult, type SaveGameDataResponse, type StorageAdapter, type TelemetryAdditionalData, type TelemetryConfig, type TelemetryEvent, generateUUID, handleVerifyMessage, isDomainAllowed, logger, parseUrlParams, validateSignature, verifyAuthentication, verifyHyveToken };
package/dist/index.js CHANGED
@@ -29,6 +29,7 @@ __export(index_exports, {
29
29
  Logger: () => Logger,
30
30
  NativeBridge: () => NativeBridge,
31
31
  NativeMessageType: () => NativeMessageType,
32
+ PlaygamaService: () => PlaygamaService,
32
33
  generateUUID: () => generateUUID,
33
34
  handleVerifyMessage: () => handleVerifyMessage,
34
35
  isDomainAllowed: () => isDomainAllowed,
@@ -799,6 +800,133 @@ var AdsService = class {
799
800
  }
800
801
  };
801
802
 
803
+ // src/services/playgama.ts
804
+ var PLAYGAMA_BRIDGE_CDN = "https://bridge.playgama.com/v1/stable/playgama-bridge.js";
805
+ var PlaygamaService = class {
806
+ initialized = false;
807
+ /**
808
+ * Detects if the game is running on the Playgama platform.
809
+ * Playgama injects a `platform_id=playgama` URL parameter into the game URL.
810
+ * Falls back to checking document.referrer for playgama.com.
811
+ */
812
+ static isPlaygamaDomain() {
813
+ try {
814
+ const url = new URL(window.location.href);
815
+ if (url.searchParams.get("platform_id") === "playgama") {
816
+ return true;
817
+ }
818
+ if (document.referrer.includes("playgama.com")) {
819
+ return true;
820
+ }
821
+ if (window !== window.top) {
822
+ try {
823
+ if (window.parent.location.hostname.includes("playgama.com")) {
824
+ return true;
825
+ }
826
+ } catch {
827
+ }
828
+ }
829
+ return false;
830
+ } catch {
831
+ return false;
832
+ }
833
+ }
834
+ /**
835
+ * Loads the Playgama Bridge script from CDN and initializes it.
836
+ * Safe to call multiple times - resolves immediately if already initialized.
837
+ */
838
+ async initialize() {
839
+ if (this.initialized) return true;
840
+ try {
841
+ await this.loadScript();
842
+ await window.bridge.initialize();
843
+ this.initialized = true;
844
+ return true;
845
+ } catch (error) {
846
+ console.warn("[PlaygamaService] Failed to initialize:", error);
847
+ return false;
848
+ }
849
+ }
850
+ isInitialized() {
851
+ return this.initialized;
852
+ }
853
+ async showInterstitial() {
854
+ const requestedAt = Date.now();
855
+ if (!this.initialized || !window.bridge) {
856
+ return {
857
+ success: false,
858
+ type: "interstitial",
859
+ error: new Error("Playgama not initialized"),
860
+ requestedAt,
861
+ completedAt: Date.now()
862
+ };
863
+ }
864
+ return new Promise((resolve) => {
865
+ const handler = (state) => {
866
+ if (state === "closed") {
867
+ window.bridge.advertisement.off("interstitial_state_changed", handler);
868
+ resolve({ success: true, type: "interstitial", requestedAt, completedAt: Date.now() });
869
+ } else if (state === "failed") {
870
+ window.bridge.advertisement.off("interstitial_state_changed", handler);
871
+ resolve({
872
+ success: false,
873
+ type: "interstitial",
874
+ error: new Error("Interstitial ad failed"),
875
+ requestedAt,
876
+ completedAt: Date.now()
877
+ });
878
+ }
879
+ };
880
+ window.bridge.advertisement.on("interstitial_state_changed", handler);
881
+ window.bridge.advertisement.showInterstitial();
882
+ });
883
+ }
884
+ async showRewarded() {
885
+ const requestedAt = Date.now();
886
+ if (!this.initialized || !window.bridge) {
887
+ return {
888
+ success: false,
889
+ type: "rewarded",
890
+ error: new Error("Playgama not initialized"),
891
+ requestedAt,
892
+ completedAt: Date.now()
893
+ };
894
+ }
895
+ return new Promise((resolve) => {
896
+ let rewarded = false;
897
+ const handler = (state) => {
898
+ if (state === "rewarded") {
899
+ rewarded = true;
900
+ } else if (state === "closed" || state === "failed") {
901
+ window.bridge.advertisement.off("rewarded_state_changed", handler);
902
+ resolve({
903
+ success: rewarded,
904
+ type: "rewarded",
905
+ error: !rewarded ? new Error("Rewarded ad not completed") : void 0,
906
+ requestedAt,
907
+ completedAt: Date.now()
908
+ });
909
+ }
910
+ };
911
+ window.bridge.advertisement.on("rewarded_state_changed", handler);
912
+ window.bridge.advertisement.showRewarded();
913
+ });
914
+ }
915
+ loadScript() {
916
+ return new Promise((resolve, reject) => {
917
+ if (window.bridge) {
918
+ resolve();
919
+ return;
920
+ }
921
+ const script = document.createElement("script");
922
+ script.src = PLAYGAMA_BRIDGE_CDN;
923
+ script.onload = () => resolve();
924
+ script.onerror = () => reject(new Error("Failed to load Playgama Bridge script"));
925
+ document.head.appendChild(script);
926
+ });
927
+ }
928
+ };
929
+
802
930
  // src/services/billing.ts
803
931
  var BillingPlatform = /* @__PURE__ */ ((BillingPlatform3) => {
804
932
  BillingPlatform3["WEB"] = "web";
@@ -1510,6 +1638,7 @@ var HyveClient = class {
1510
1638
  jwtToken = null;
1511
1639
  gameId = null;
1512
1640
  adsService;
1641
+ playgamaService = null;
1513
1642
  billingService;
1514
1643
  billingConfig;
1515
1644
  // Store callbacks to preserve them when recreating BillingService
@@ -1537,6 +1666,12 @@ var HyveClient = class {
1537
1666
  if (config?.ads) {
1538
1667
  this.adsService.configure(config.ads);
1539
1668
  }
1669
+ if (typeof window !== "undefined" && PlaygamaService.isPlaygamaDomain()) {
1670
+ this.playgamaService = new PlaygamaService();
1671
+ this.playgamaService.initialize().then((success) => {
1672
+ logger.info("Playgama Bridge initialized:", success);
1673
+ });
1674
+ }
1540
1675
  this.billingConfig = config?.billing || {};
1541
1676
  this.billingService = new BillingService(this.billingConfig);
1542
1677
  this.storageMode = config?.storageMode || "cloud";
@@ -1556,6 +1691,7 @@ var HyveClient = class {
1556
1691
  );
1557
1692
  logger.info("API Base URL:", this.apiBaseUrl);
1558
1693
  logger.info("Ads enabled:", this.adsService.isEnabled());
1694
+ logger.info("Playgama platform:", this.playgamaService !== null);
1559
1695
  logger.info(
1560
1696
  "Billing configured:",
1561
1697
  Object.keys(this.billingConfig).length > 0
@@ -1985,6 +2121,10 @@ var HyveClient = class {
1985
2121
  * @returns Promise resolving to ad result
1986
2122
  */
1987
2123
  async showAd(type) {
2124
+ if (this.playgamaService?.isInitialized()) {
2125
+ if (type === "rewarded") return this.playgamaService.showRewarded();
2126
+ return this.playgamaService.showInterstitial();
2127
+ }
1988
2128
  return this.adsService.show(type);
1989
2129
  }
1990
2130
  /**
@@ -2114,6 +2254,7 @@ var HyveClient = class {
2114
2254
  Logger,
2115
2255
  NativeBridge,
2116
2256
  NativeMessageType,
2257
+ PlaygamaService,
2117
2258
  generateUUID,
2118
2259
  handleVerifyMessage,
2119
2260
  isDomainAllowed,
package/dist/index.mjs CHANGED
@@ -757,6 +757,133 @@ var AdsService = class {
757
757
  }
758
758
  };
759
759
 
760
+ // src/services/playgama.ts
761
+ var PLAYGAMA_BRIDGE_CDN = "https://bridge.playgama.com/v1/stable/playgama-bridge.js";
762
+ var PlaygamaService = class {
763
+ initialized = false;
764
+ /**
765
+ * Detects if the game is running on the Playgama platform.
766
+ * Playgama injects a `platform_id=playgama` URL parameter into the game URL.
767
+ * Falls back to checking document.referrer for playgama.com.
768
+ */
769
+ static isPlaygamaDomain() {
770
+ try {
771
+ const url = new URL(window.location.href);
772
+ if (url.searchParams.get("platform_id") === "playgama") {
773
+ return true;
774
+ }
775
+ if (document.referrer.includes("playgama.com")) {
776
+ return true;
777
+ }
778
+ if (window !== window.top) {
779
+ try {
780
+ if (window.parent.location.hostname.includes("playgama.com")) {
781
+ return true;
782
+ }
783
+ } catch {
784
+ }
785
+ }
786
+ return false;
787
+ } catch {
788
+ return false;
789
+ }
790
+ }
791
+ /**
792
+ * Loads the Playgama Bridge script from CDN and initializes it.
793
+ * Safe to call multiple times - resolves immediately if already initialized.
794
+ */
795
+ async initialize() {
796
+ if (this.initialized) return true;
797
+ try {
798
+ await this.loadScript();
799
+ await window.bridge.initialize();
800
+ this.initialized = true;
801
+ return true;
802
+ } catch (error) {
803
+ console.warn("[PlaygamaService] Failed to initialize:", error);
804
+ return false;
805
+ }
806
+ }
807
+ isInitialized() {
808
+ return this.initialized;
809
+ }
810
+ async showInterstitial() {
811
+ const requestedAt = Date.now();
812
+ if (!this.initialized || !window.bridge) {
813
+ return {
814
+ success: false,
815
+ type: "interstitial",
816
+ error: new Error("Playgama not initialized"),
817
+ requestedAt,
818
+ completedAt: Date.now()
819
+ };
820
+ }
821
+ return new Promise((resolve) => {
822
+ const handler = (state) => {
823
+ if (state === "closed") {
824
+ window.bridge.advertisement.off("interstitial_state_changed", handler);
825
+ resolve({ success: true, type: "interstitial", requestedAt, completedAt: Date.now() });
826
+ } else if (state === "failed") {
827
+ window.bridge.advertisement.off("interstitial_state_changed", handler);
828
+ resolve({
829
+ success: false,
830
+ type: "interstitial",
831
+ error: new Error("Interstitial ad failed"),
832
+ requestedAt,
833
+ completedAt: Date.now()
834
+ });
835
+ }
836
+ };
837
+ window.bridge.advertisement.on("interstitial_state_changed", handler);
838
+ window.bridge.advertisement.showInterstitial();
839
+ });
840
+ }
841
+ async showRewarded() {
842
+ const requestedAt = Date.now();
843
+ if (!this.initialized || !window.bridge) {
844
+ return {
845
+ success: false,
846
+ type: "rewarded",
847
+ error: new Error("Playgama not initialized"),
848
+ requestedAt,
849
+ completedAt: Date.now()
850
+ };
851
+ }
852
+ return new Promise((resolve) => {
853
+ let rewarded = false;
854
+ const handler = (state) => {
855
+ if (state === "rewarded") {
856
+ rewarded = true;
857
+ } else if (state === "closed" || state === "failed") {
858
+ window.bridge.advertisement.off("rewarded_state_changed", handler);
859
+ resolve({
860
+ success: rewarded,
861
+ type: "rewarded",
862
+ error: !rewarded ? new Error("Rewarded ad not completed") : void 0,
863
+ requestedAt,
864
+ completedAt: Date.now()
865
+ });
866
+ }
867
+ };
868
+ window.bridge.advertisement.on("rewarded_state_changed", handler);
869
+ window.bridge.advertisement.showRewarded();
870
+ });
871
+ }
872
+ loadScript() {
873
+ return new Promise((resolve, reject) => {
874
+ if (window.bridge) {
875
+ resolve();
876
+ return;
877
+ }
878
+ const script = document.createElement("script");
879
+ script.src = PLAYGAMA_BRIDGE_CDN;
880
+ script.onload = () => resolve();
881
+ script.onerror = () => reject(new Error("Failed to load Playgama Bridge script"));
882
+ document.head.appendChild(script);
883
+ });
884
+ }
885
+ };
886
+
760
887
  // src/services/billing.ts
761
888
  var BillingPlatform = /* @__PURE__ */ ((BillingPlatform3) => {
762
889
  BillingPlatform3["WEB"] = "web";
@@ -1468,6 +1595,7 @@ var HyveClient = class {
1468
1595
  jwtToken = null;
1469
1596
  gameId = null;
1470
1597
  adsService;
1598
+ playgamaService = null;
1471
1599
  billingService;
1472
1600
  billingConfig;
1473
1601
  // Store callbacks to preserve them when recreating BillingService
@@ -1495,6 +1623,12 @@ var HyveClient = class {
1495
1623
  if (config?.ads) {
1496
1624
  this.adsService.configure(config.ads);
1497
1625
  }
1626
+ if (typeof window !== "undefined" && PlaygamaService.isPlaygamaDomain()) {
1627
+ this.playgamaService = new PlaygamaService();
1628
+ this.playgamaService.initialize().then((success) => {
1629
+ logger.info("Playgama Bridge initialized:", success);
1630
+ });
1631
+ }
1498
1632
  this.billingConfig = config?.billing || {};
1499
1633
  this.billingService = new BillingService(this.billingConfig);
1500
1634
  this.storageMode = config?.storageMode || "cloud";
@@ -1514,6 +1648,7 @@ var HyveClient = class {
1514
1648
  );
1515
1649
  logger.info("API Base URL:", this.apiBaseUrl);
1516
1650
  logger.info("Ads enabled:", this.adsService.isEnabled());
1651
+ logger.info("Playgama platform:", this.playgamaService !== null);
1517
1652
  logger.info(
1518
1653
  "Billing configured:",
1519
1654
  Object.keys(this.billingConfig).length > 0
@@ -1943,6 +2078,10 @@ var HyveClient = class {
1943
2078
  * @returns Promise resolving to ad result
1944
2079
  */
1945
2080
  async showAd(type) {
2081
+ if (this.playgamaService?.isInitialized()) {
2082
+ if (type === "rewarded") return this.playgamaService.showRewarded();
2083
+ return this.playgamaService.showInterstitial();
2084
+ }
1946
2085
  return this.adsService.show(type);
1947
2086
  }
1948
2087
  /**
@@ -2071,6 +2210,7 @@ export {
2071
2210
  Logger,
2072
2211
  NativeBridge,
2073
2212
  NativeMessageType,
2213
+ PlaygamaService,
2074
2214
  generateUUID,
2075
2215
  handleVerifyMessage,
2076
2216
  isDomainAllowed,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyve-sdk/js",
3
- "version": "1.4.1",
3
+ "version": "1.5.0",
4
4
  "description": "Hyve SDK - TypeScript wrapper for Hyve game server integration",
5
5
  "private": false,
6
6
  "publishConfig": {