@goodgamestudios/cxf-webshop 7.1.0-qa.1 → 7.1.0-qa.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.
@@ -33,7 +33,7 @@
33
33
  var define_process_default;
34
34
  var init_define_process = __esm({
35
35
  "<define:process>"() {
36
- define_process_default = { env: { BASE_URL: "http://localhost:1101", CANVAS_AGENT_URL: "https://app-dev.canvas.stillfront.com/agent.js", CANVAS_APP_ID_BY_GAME: { "12": "dae760ab-b773-4c1a-ae99-7633f12ec7d5", "15": "d57bb239-6e02-4e17-8148-0a10c4dd75f6", "16": "18f5521d-7df2-4bb3-88a3-c162ba072d73" }, CUSTOMIZATION_URL_TEMPLATE: "https://cdn.jsdelivr.net/npm/@lemonstand.org/config-goodgamestudios@{1}/dist/goodgamestudios-{0}.json", CUSTOMIZATION_URL: "https://cdn.jsdelivr.net/npm/@lemonstand.org/config-goodgamestudios@qa/dist/goodgamestudios-{0}.json" } };
36
+ define_process_default = { env: { BASE_URL: { "12": "https://ef-canvas-test.public.ggs-ep.com", "15": "https://canvas-test.goodgamestudios.com", "16": "https://ef-canvas-test.public.ggs-ep.com", default: "https://canvas-test.goodgamestudios.com" }, CANVAS_AGENT_URL: "https://app-test.canvas.stillfront.com/agent.js", CANVAS_APP_ID_BY_GAME: { "12": "81199abb-592e-465c-b926-8656628a64c7", "15": { google: "25facd0c-e850-4ebf-b6c4-8c60240e4cf8", stillpay: "bec451f9-8db4-4ca1-8a5a-54494429ff5e" }, "16": "18f5521d-7df2-4bb3-88a3-c162ba072d73" }, CUSTOMIZATION_URL_TEMPLATE: "https://cdn.jsdelivr.net/npm/@lemonstand.org/config-goodgamestudios@{1}/dist/goodgamestudios-{0}.json", CUSTOMIZATION_URL: "https://cdn.jsdelivr.net/npm/@lemonstand.org/config-goodgamestudios@qa/dist/goodgamestudios-{0}.json" } };
37
37
  }
38
38
  });
39
39
 
@@ -622,52 +622,89 @@
622
622
  // src/fetch.ts
623
623
  init_define_process();
624
624
 
625
- // src/helpers.ts
625
+ // src/store.ts
626
626
  init_define_process();
627
+ function initializeStore(cxf) {
628
+ return {
629
+ isCanvas: false,
630
+ playerId: cxf.playerId,
631
+ instanceId: cxf.instanceId,
632
+ networkId: cxf.networkId,
633
+ gameId: cxf.gameId,
634
+ gameApi: cxf.gameApi,
635
+ language: cxf.language,
636
+ token: cxf.token,
637
+ zoneId: cxf.zoneId,
638
+ gameEvents: [],
639
+ xp: 0,
640
+ level: 0,
641
+ legendLevel: void 0,
642
+ countryCode: "",
643
+ lastPurchaseTab: "",
644
+ subscriptionDisabled: false,
645
+ isTempServer: false,
646
+ customizationSuffix: "",
647
+ resolvedCustomizationUrl: "",
648
+ sourceId: "unknown",
649
+ unreadOfferNotifsCountUrl: ""
650
+ };
651
+ }
652
+ function criteriaSelector({ legendLevel, level }) {
653
+ return {
654
+ legendLevel,
655
+ level
656
+ };
657
+ }
627
658
 
628
- // node_modules/@lukeed/uuid/dist/index.mjs
659
+ // src/utils/index.ts
629
660
  init_define_process();
630
- var IDX = 256;
631
- var HEX = [];
632
- var BUFFER;
633
- while (IDX--) HEX[IDX] = (IDX + 256).toString(16).substring(1);
634
- function v4() {
635
- var i = 0, num, out = "";
636
- if (!BUFFER || IDX + 16 > 256) {
637
- BUFFER = Array(i = 256);
638
- while (i--) BUFFER[i] = 256 * Math.random() | 0;
639
- i = IDX = 0;
661
+
662
+ // src/utils/domain.ts
663
+ init_define_process();
664
+ var parentDomain = (referrer) => {
665
+ const matches = referrer.match(/^https?:\/\/([^#/?]+)(?:[#/?]|$)/i);
666
+ if (!matches || !matches[1]) {
667
+ return;
640
668
  }
641
- for (; i < 16; i++) {
642
- num = BUFFER[IDX + i];
643
- if (i == 6) out += HEX[num & 15 | 64];
644
- else if (i == 8) out += HEX[num & 63 | 128];
645
- else out += HEX[num];
646
- if (i & 1 && i > 1 && i < 11) out += "-";
669
+ const result = matches[1].match(/[^.]+\.[^.]+$/);
670
+ if (!result) {
671
+ return;
647
672
  }
648
- IDX++;
649
- return out;
650
- }
673
+ return result[0];
674
+ };
675
+ var getDomain = (referrer) => {
676
+ return parentDomain(referrer);
677
+ };
651
678
 
652
- // src/helpers.ts
653
- var import_debug = __toESM(require_browser());
679
+ // src/utils/error-handling.ts
680
+ init_define_process();
654
681
 
655
- // src/ArgumentNullError.ts
682
+ // src/utils/logging.ts
656
683
  init_define_process();
657
- var ArgumentNullError = class extends Error {
658
- constructor(parameterName, parameterValue) {
659
- super(`${parameterName} has null value: ${parameterValue}`);
660
- this.name = "ArgumentNullError";
684
+ var import_debug = __toESM(require_browser());
685
+ var logger = (0, import_debug.default)("CXF-WEBSHOP");
686
+ var log = (argument0, ...rest) => logger(argument0, ...rest);
687
+ var logError = (...arguments_) => (
688
+ // tslint:disable-next-line:no-console
689
+ console.error("%c CXF-WEBSHOP ->", "background: #ff0000; color: #fff", ...arguments_)
690
+ );
691
+
692
+ // src/utils/error-handling.ts
693
+ var tryCatch = (fn) => (...args) => {
694
+ try {
695
+ return fn(...args);
696
+ } catch (error) {
697
+ logError(error);
698
+ throwCxfError(error);
661
699
  }
662
700
  };
701
+ var throwCxfError = (e) => {
702
+ const config = globalState.getConfig();
703
+ const cxf = globalState.getCxf();
704
+ cxf.emit(config.CXF_ERROR, e);
705
+ };
663
706
 
664
- // src/types/models.ts
665
- init_define_process();
666
- function encodeGnip({ gameId, networkId, instanceId, playerId }) {
667
- return [gameId, networkId, instanceId, playerId].join("-");
668
- }
669
-
670
- // src/utils.ts
707
+ // src/utils/loaders.ts
671
708
  init_define_process();
672
709
  var startTimer = (function_, time) => {
673
710
  const id = setTimeout(function_, time);
@@ -684,62 +721,6 @@
684
721
  }).catch(reject);
685
722
  });
686
723
  };
687
- var validateForNull = (properties) => {
688
- for (const key of Object.keys(properties)) {
689
- const value = properties[key];
690
- if (value === void 0 || value === null || Number.isNaN(value)) {
691
- throw new ArgumentNullError(key, value);
692
- }
693
- }
694
- };
695
- function msToSec(value) {
696
- return Math.floor(value / 1e3);
697
- }
698
- var parentDomain = (referrer) => {
699
- const matches = referrer.match(/^https?:\/\/([^#/?]+)(?:[#/?]|$)/i);
700
- if (!matches || !matches[1]) {
701
- return;
702
- }
703
- const result = matches[1].match(/[^.]+\.[^.]+$/);
704
- if (!result) {
705
- return;
706
- }
707
- return result[0];
708
- };
709
-
710
- // src/helpers.ts
711
- var detectPlatform = (defaultPlatform = "stillpay") => {
712
- const nativePlatform = navigator.userAgent.match(
713
- /(itunes)|(googleplay)|(Android)|(amazonmobile)|(facebook)|(samsung)|(huawei)/g
714
- );
715
- if (!nativePlatform) return defaultPlatform;
716
- const activePlatform = nativePlatform[0];
717
- const distribPlatforms = {
718
- itunes: "apple",
719
- Android: "google",
720
- googleplay: "google",
721
- amazonmobile: "amazon",
722
- facebook: "facebook",
723
- samsung: "samsung",
724
- huawei: "huawei"
725
- };
726
- return Object.prototype.hasOwnProperty.call(distribPlatforms, activePlatform) ? distribPlatforms[activePlatform] : defaultPlatform;
727
- };
728
- function formatQueryString(object) {
729
- return Object.entries(object).filter(([key, value]) => value !== null && value !== void 0).map(([key, value]) => `${key}=${encodeURIComponent(value)}`).join("&");
730
- }
731
- var getTokenAndLanguage = (store) => {
732
- const { playerId, token, zoneId, language } = store;
733
- if (!playerId) {
734
- throw new ArgumentNullError("playerId", playerId);
735
- }
736
- return {
737
- token,
738
- zoneId,
739
- locale: language,
740
- ping: encodeGnip({ ...store, playerId })
741
- };
742
- };
743
724
  var loadScript = (src) => new Promise((resolve, reject) => {
744
725
  const script = document.createElement("script");
745
726
  script.type = "text/javascript";
@@ -750,36 +731,10 @@
750
731
  script.addEventListener("error", reject);
751
732
  document.body.append(script);
752
733
  });
753
- var tryCatch = (fn) => (...args) => {
754
- try {
755
- return fn(...args);
756
- } catch (error) {
757
- logError(error);
758
- throwCxfError(error);
759
- }
760
- };
761
- var throwCxfError = (e) => {
762
- const config = globalState.getConfig();
763
- const cxf = globalState.getCxf();
764
- cxf.emit(config.CXF_ERROR, e);
765
- };
766
734
  var loadCxf = timeout(() => require_dist(), 1e4);
767
- var logger = (0, import_debug.default)("CXF-WEBSHOP");
768
- var log = (argument0, ...rest) => logger(argument0, ...rest);
769
- var logError = (...arguments_) => (
770
- // tslint:disable-next-line:no-console
771
- console.error("%c CXF-WEBSHOP ->", "background: #ff0000; color: #fff", ...arguments_)
772
- );
773
- var createSessionId = () => v4();
774
- var getDomain = (referrer) => {
775
- return parentDomain(referrer);
776
- };
777
- var ggsGetQueryParams = () => {
778
- return ggsGetQueryParameters();
779
- };
780
- var ggsGetReferrerValue = () => {
781
- return ggsGetReferrer();
782
- };
735
+
736
+ // src/utils/payment.ts
737
+ init_define_process();
783
738
  var transformPaymentContractIdsToNativePriceEvent = (ids) => (
784
739
  // eslint-disable-next-line unicorn/no-array-reduce
785
740
  ids.reduce(
@@ -802,93 +757,205 @@
802
757
  )
803
758
  );
804
759
 
805
- // src/store.ts
760
+ // src/utils/platform.ts
806
761
  init_define_process();
807
- function initializeStore(cxf) {
762
+ var userAgentToDistribPlatformMatrix = {
763
+ itunes: "apple",
764
+ Android: "google",
765
+ googleplay: "google",
766
+ amazonmobile: "amazon",
767
+ facebook: "facebook",
768
+ samsung: "samsung",
769
+ huawei: "huawei"
770
+ };
771
+ var detectPlatform = (defaultPlatform = "stillpay") => {
772
+ const nativePlatform = navigator.userAgent.match(
773
+ /(itunes)|(googleplay)|(Android)|(amazonmobile)|(facebook)|(samsung)|(huawei)/g
774
+ );
775
+ if (!nativePlatform) return defaultPlatform;
776
+ const activePlatform = nativePlatform[0];
777
+ return Object.prototype.hasOwnProperty.call(userAgentToDistribPlatformMatrix, activePlatform) ? userAgentToDistribPlatformMatrix[activePlatform] : defaultPlatform;
778
+ };
779
+ var distribPlatformToProviderMatrix = {
780
+ apple: "itunes",
781
+ google: "googleplay",
782
+ amazon: "amazonmobile",
783
+ facebook: "facebook",
784
+ samsung: "samsung",
785
+ huawei: "huawei"
786
+ };
787
+ var createProductIdsForPlatform = (platform, id) => {
788
+ if (!Object.prototype.hasOwnProperty.call(distribPlatformToProviderMatrix, platform))
789
+ throw new Error(`Platform ${platform} is not supported`);
790
+ const res = /* @__PURE__ */ Object.create(null);
791
+ res[distribPlatformToProviderMatrix[platform]] = id;
792
+ return res;
793
+ };
794
+
795
+ // src/utils/query-params.ts
796
+ init_define_process();
797
+ function formatQueryString(object) {
798
+ return Object.entries(object).filter(([key, value]) => value !== null && value !== void 0).map(([key, value]) => `${key}=${encodeURIComponent(value)}`).join("&");
799
+ }
800
+ var ggsGetQueryParams = () => {
801
+ return ggsGetQueryParameters();
802
+ };
803
+ var ggsGetReferrerValue = () => {
804
+ return ggsGetReferrer();
805
+ };
806
+
807
+ // src/utils/session.ts
808
+ init_define_process();
809
+
810
+ // node_modules/@lukeed/uuid/dist/index.mjs
811
+ init_define_process();
812
+ var IDX = 256;
813
+ var HEX = [];
814
+ var BUFFER;
815
+ while (IDX--) HEX[IDX] = (IDX + 256).toString(16).substring(1);
816
+ function v4() {
817
+ var i = 0, num, out = "";
818
+ if (!BUFFER || IDX + 16 > 256) {
819
+ BUFFER = Array(i = 256);
820
+ while (i--) BUFFER[i] = 256 * Math.random() | 0;
821
+ i = IDX = 0;
822
+ }
823
+ for (; i < 16; i++) {
824
+ num = BUFFER[IDX + i];
825
+ if (i == 6) out += HEX[num & 15 | 64];
826
+ else if (i == 8) out += HEX[num & 63 | 128];
827
+ else out += HEX[num];
828
+ if (i & 1 && i > 1 && i < 11) out += "-";
829
+ }
830
+ IDX++;
831
+ return out;
832
+ }
833
+
834
+ // src/ArgumentNullError.ts
835
+ init_define_process();
836
+ var ArgumentNullError = class extends Error {
837
+ constructor(parameterName, parameterValue) {
838
+ super(`${parameterName} has null value: ${parameterValue}`);
839
+ this.name = "ArgumentNullError";
840
+ }
841
+ };
842
+
843
+ // src/types/models.ts
844
+ init_define_process();
845
+ function encodeGnip({ gameId, networkId, instanceId, playerId }) {
846
+ return [gameId, networkId, instanceId, playerId].join("-");
847
+ }
848
+
849
+ // src/utils/session.ts
850
+ var createSessionId = () => v4();
851
+ var getTokenAndLanguage = (store) => {
852
+ const { playerId, token, zoneId, language } = store;
853
+ if (!playerId) {
854
+ throw new ArgumentNullError("playerId", playerId);
855
+ }
808
856
  return {
809
- isCanvas: false,
810
- playerId: cxf.playerId,
811
- instanceId: cxf.instanceId,
812
- networkId: cxf.networkId,
813
- gameId: cxf.gameId,
814
- gameApi: cxf.gameApi,
815
- language: cxf.language,
816
- token: cxf.token,
817
- zoneId: cxf.zoneId,
818
- gameEvents: [],
819
- xp: 0,
820
- level: 0,
821
- legendLevel: void 0,
822
- countryCode: "",
823
- lastPurchaseTab: "",
824
- subscriptionDisabled: false,
825
- isTempServer: false,
826
- customizationSuffix: "",
827
- resolvedCustomizationUrl: "",
828
- sourceId: "unknown",
829
- unreadOfferNotifsCountUrl: ""
857
+ token,
858
+ zoneId,
859
+ locale: language,
860
+ ping: encodeGnip({ ...store, playerId })
830
861
  };
862
+ };
863
+
864
+ // src/utils/time.ts
865
+ init_define_process();
866
+ function msToSec(value) {
867
+ return Math.floor(value / 1e3);
831
868
  }
832
- function criteriaSelector({ legendLevel, level }) {
869
+
870
+ // src/utils/url.ts
871
+ init_define_process();
872
+ var import_game_alias = __toESM(require_dist2());
873
+
874
+ // src/config.ts
875
+ init_define_process();
876
+ var import_cxf_events = __toESM(require_typings());
877
+
878
+ // src/types/index.ts
879
+ init_define_process();
880
+
881
+ // src/types/config.ts
882
+ init_define_process();
883
+
884
+ // src/types/store.ts
885
+ init_define_process();
886
+ var entityProvider = (initial) => {
887
+ let element = initial;
833
888
  return {
834
- legendLevel,
835
- level
889
+ get: () => element,
890
+ set: (value) => {
891
+ element = value;
892
+ }
836
893
  };
837
- }
894
+ };
838
895
 
839
- // src/fetch.ts
840
- var fetchUnreadOfferNotificationsCount = async () => {
841
- const config = globalState.getConfig();
842
- const store = globalState.getStore();
843
- if (config.LEGEND_LEVEL_IS_USED && store.legendLevel === void 0) {
844
- log("Skip fetchUnreadOfferNotificationsCount due to legendLevel is undefined");
845
- return;
846
- }
847
- if (!store.isCanvas && store.token && store.unreadOfferNotifsCountUrl) {
848
- log("fetchUnreadOfferNotificationsCount");
849
- let unreadCount = 0;
850
- const headers = {
851
- Authorization: `Bearer ${store.token}`
852
- };
853
- const url = store.unreadOfferNotifsCountUrl.replace("{locale}", store.language || "").replace("{zoneId}", store.zoneId || "").replace("{criteria}", encodeURIComponent(JSON.stringify(criteriaSelector(store))));
896
+ // src/config.ts
897
+ var parseBaseUrl = (value) => {
898
+ if (typeof value === "string") {
854
899
  try {
855
- log("fetch", url);
856
- const resp = await fetch(url, {
857
- headers
858
- });
859
- if (resp.ok) {
860
- const data = await resp.json();
861
- unreadCount = Number(data?.notifCount);
862
- }
863
- } catch (error) {
864
- logError(`cannot fetch ${url}`, error);
900
+ return JSON.parse(value);
901
+ } catch {
902
+ return { default: value };
865
903
  }
866
- log("setUnseenOffersCounter", unreadCount);
867
- store.gameApi.invokeFn("setUnseenOffersCounter", unreadCount).catch((error) => {
868
- logError("setUnseenOffersCounter error:", error);
869
- });
870
904
  }
905
+ return value || { default: "" };
906
+ };
907
+ var COMMON_CONFIG = {
908
+ CANVAS_AGENT_URL: define_process_default.env.CANVAS_AGENT_URL,
909
+ CANVAS_APP_ID_BY_GAME: define_process_default.env.CANVAS_APP_ID_BY_GAME,
910
+ CUSTOMIZATION_URL: define_process_default.env.CUSTOMIZATION_URL,
911
+ CUSTOMIZATION_URL_TEMPLATE: define_process_default.env.CUSTOMIZATION_URL_TEMPLATE,
912
+ BASE_URL: parseBaseUrl(define_process_default.env.BASE_URL),
913
+ CXF_DIALOG_OPEN: "cxf.dialog.open",
914
+ CXF_DIALOG_CLOSE: "cxf.dialog.close",
915
+ CXF_TRACK_MSG: "cxf.tracking.message",
916
+ CXF_BTN_CLICK_MSG: import_cxf_events.CxfEvents.OpenIGS,
917
+ CXF_OPEN_SALES_MSG: "cxf.webshop.sales.open" /* CXF_OPEN_SALES_MSG */,
918
+ WEB_SHOP_CALL_TRACK_ID: 1181,
919
+ CXF_ERROR: "cxf.error",
920
+ CXF_PUSH: "cxf.push",
921
+ CXF_AD_STATUS: "cxf.adBanner.status"
922
+ };
923
+ var GAME_SPECIFIC_CONFIG = {
924
+ 12: {
925
+ LEGEND_LEVEL_IS_USED: true
926
+ },
927
+ 15: {
928
+ LEGEND_LEVEL_IS_USED: false
929
+ },
930
+ 16: {
931
+ LEGEND_LEVEL_IS_USED: true
932
+ }
933
+ };
934
+ var createConfig = (gameId) => {
935
+ return {
936
+ ...COMMON_CONFIG,
937
+ ...GAME_SPECIFIC_CONFIG[gameId]
938
+ };
939
+ };
940
+ var getBaseUrlForGame = (gameId) => {
941
+ const baseUrl = COMMON_CONFIG.BASE_URL;
942
+ const gameIdKey = String(gameId);
943
+ return baseUrl[gameIdKey] || baseUrl.default || "";
871
944
  };
872
945
 
873
- // src/messages/ShopMessageBus.ts
946
+ // src/utils/validation.ts
874
947
  init_define_process();
875
- var ShopMessageBus = class {
876
- post(message) {
877
- const element = document.querySelector("#dialog");
878
- if (element && element.tagName.toLocaleLowerCase() === "iframe") {
879
- element.contentWindow?.postMessage(message, "*");
948
+ var validateForNull = (properties) => {
949
+ for (const key of Object.keys(properties)) {
950
+ const value = properties[key];
951
+ if (value === void 0 || value === null || Number.isNaN(value)) {
952
+ throw new ArgumentNullError(key, value);
880
953
  }
881
954
  }
882
955
  };
883
956
 
884
- // src/preFetch.ts
885
- init_define_process();
886
-
887
- // src/url.ts
888
- init_define_process();
889
- var import_game_alias = __toESM(require_dist2());
957
+ // src/utils/url.ts
890
958
  var createIframeUrl = ({ page, route, sid, config: igsConfig = {} }) => {
891
- const config = globalState.getConfig();
892
959
  const store = globalState.getStore();
893
960
  const { token, zoneId, locale } = getTokenAndLanguage(store);
894
961
  const parameters = {
@@ -917,7 +984,8 @@
917
984
  if (store.adStatus?.areBannersAvailable) {
918
985
  queryParameters.ads = true;
919
986
  }
920
- return `${config.BASE_URL}/?${formatQueryString(queryParameters)}${page ? `#${page}` : ""}${route ? `--${route}--${Date.now()}` : ""}`;
987
+ const baseUrl = getBaseUrlForGame(store.gameId);
988
+ return `${baseUrl}/?${formatQueryString(queryParameters)}${page ? `#${page}` : ""}${route ? `--${route}--${Date.now()}` : ""}`;
921
989
  };
922
990
  var createCustomizationUrl = () => {
923
991
  const config = globalState.getConfig();
@@ -935,7 +1003,53 @@
935
1003
  return config.CUSTOMIZATION_URL.replace("{0}", configBranch);
936
1004
  };
937
1005
 
1006
+ // src/fetch.ts
1007
+ var fetchUnreadOfferNotificationsCount = async () => {
1008
+ const config = globalState.getConfig();
1009
+ const store = globalState.getStore();
1010
+ if (config.LEGEND_LEVEL_IS_USED && store.legendLevel === void 0) {
1011
+ log("Skip fetchUnreadOfferNotificationsCount due to legendLevel is undefined");
1012
+ return;
1013
+ }
1014
+ if (!store.isCanvas && store.token && store.unreadOfferNotifsCountUrl) {
1015
+ log("fetchUnreadOfferNotificationsCount");
1016
+ let unreadCount = 0;
1017
+ const headers = {
1018
+ Authorization: `Bearer ${store.token}`
1019
+ };
1020
+ const url = store.unreadOfferNotifsCountUrl.replace("{locale}", store.language || "").replace("{zoneId}", store.zoneId || "").replace("{criteria}", encodeURIComponent(JSON.stringify(criteriaSelector(store))));
1021
+ try {
1022
+ log("fetch", url);
1023
+ const resp = await fetch(url, {
1024
+ headers
1025
+ });
1026
+ if (resp.ok) {
1027
+ const data = await resp.json();
1028
+ unreadCount = Number(data?.notifCount);
1029
+ }
1030
+ } catch (error) {
1031
+ logError(`cannot fetch ${url}`, error);
1032
+ }
1033
+ log("setUnseenOffersCounter", unreadCount);
1034
+ store.gameApi.invokeFn("setUnseenOffersCounter", unreadCount).catch((error) => {
1035
+ logError("setUnseenOffersCounter error:", error);
1036
+ });
1037
+ }
1038
+ };
1039
+
1040
+ // src/messages/ShopMessageBus.ts
1041
+ init_define_process();
1042
+ var ShopMessageBus = class {
1043
+ post(message) {
1044
+ const element = document.querySelector("#dialog");
1045
+ if (element && element.tagName.toLocaleLowerCase() === "iframe") {
1046
+ element.contentWindow?.postMessage(message, "*");
1047
+ }
1048
+ }
1049
+ };
1050
+
938
1051
  // src/preFetch.ts
1052
+ init_define_process();
939
1053
  var preResolveConfig = () => {
940
1054
  if (typeof fetch !== "function") {
941
1055
  return;
@@ -961,18 +1075,6 @@
961
1075
  });
962
1076
  };
963
1077
 
964
- // src/types/store.ts
965
- init_define_process();
966
- var entityProvider = (initial) => {
967
- let element = initial;
968
- return {
969
- get: () => element,
970
- set: (value) => {
971
- element = value;
972
- }
973
- };
974
- };
975
-
976
1078
  // src/globalState.ts
977
1079
  var GlobalState = class {
978
1080
  constructor() {
@@ -1025,7 +1127,7 @@
1025
1127
 
1026
1128
  // src/handlers/cxfEventHandlers.ts
1027
1129
  init_define_process();
1028
- var import_cxf_events = __toESM(require_typings());
1130
+ var import_cxf_events2 = __toESM(require_typings());
1029
1131
 
1030
1132
  // src/dialog.ts
1031
1133
  init_define_process();
@@ -1064,27 +1166,9 @@
1064
1166
  cxf.emit(config.CXF_TRACK_MSG, payload);
1065
1167
  };
1066
1168
 
1067
- // src/types/index.ts
1068
- init_define_process();
1069
-
1070
- // src/types/config.ts
1071
- init_define_process();
1072
-
1073
1169
  // src/whitelist.ts
1074
1170
  init_define_process();
1075
- var whitelistedZones = /* @__PURE__ */ new Set([
1076
- // 264, Poland
1077
- 316,
1078
- 318,
1079
- 460,
1080
- 461,
1081
- 767,
1082
- 768,
1083
- 802,
1084
- 814,
1085
- 830,
1086
- 877
1087
- ]);
1171
+ var whitelistedZones = /* @__PURE__ */ new Set([218, 316, 318, 460, 461, 768, 802, 814, 830, 877]);
1088
1172
 
1089
1173
  // src/handlers/pushHandlers.ts
1090
1174
  init_define_process();
@@ -1167,7 +1251,7 @@
1167
1251
  break;
1168
1252
  }
1169
1253
  case "native_checkout_request" /* NATIVE_CHECKOUT_REQUEST */: {
1170
- const { paymentContract, sessionId, collectionAlias, offerId } = event;
1254
+ const { paymentContract, sessionId, offerId, distributionPlatform } = event;
1171
1255
  const { zoneId } = globalState.getStore();
1172
1256
  window.postMessage(
1173
1257
  {
@@ -1177,16 +1261,16 @@
1177
1261
  pkg: {
1178
1262
  price: paymentContract?.price?.amount,
1179
1263
  productIdMS: "",
1180
- productIds: { googleplay: paymentContract?.id },
1264
+ productIds: createProductIdsForPlatform(distributionPlatform, paymentContract?.id),
1181
1265
  tier: Number(paymentContract?.id?.split("_")?.at(-1))
1182
1266
  },
1183
- // !sid || !type || !zoneId || !offerId || !successUrl || !criteria
1184
1267
  meta: {
1185
- criteria: JSON.stringify({}),
1268
+ criteria: window.CanvasAgent?.instance?.getState()?.appConfig?.canvasAppId,
1186
1269
  lemonstand: true,
1187
1270
  offerId,
1188
1271
  sid: sessionId,
1189
- type: collectionAlias,
1272
+ type: "canvas",
1273
+ // IMPORTANT: type must be 'canvas'
1190
1274
  zoneId,
1191
1275
  successUrl: window.location.href
1192
1276
  }
@@ -1203,7 +1287,7 @@
1203
1287
  }
1204
1288
  };
1205
1289
  var onOpen = (payload = {}) => {
1206
- log(import_cxf_events.CxfEvents.OpenIGS, "payload:", payload);
1290
+ log(import_cxf_events2.CxfEvents.OpenIGS, "payload:", payload);
1207
1291
  if (payload.sourceId) {
1208
1292
  globalState.updateStore({
1209
1293
  sourceId: payload.sourceId
@@ -1231,18 +1315,18 @@
1231
1315
  };
1232
1316
  var subscribeToCommonCxfEvents = (cxf) => {
1233
1317
  const pushHandlers = createPushHandlers();
1234
- cxf.on(import_cxf_events.CxfEvents.OpenIGS, tryCatch(onOpen));
1318
+ cxf.on(import_cxf_events2.CxfEvents.OpenIGS, tryCatch(onOpen));
1235
1319
  cxf.on(
1236
- import_cxf_events.CxfEvents.Push,
1320
+ import_cxf_events2.CxfEvents.Push,
1237
1321
  tryCatch(({ id, payload }) => {
1238
- log(import_cxf_events.CxfEvents.Push, id, payload);
1322
+ log(import_cxf_events2.CxfEvents.Push, id, payload);
1239
1323
  const handler = pushHandlers[id];
1240
1324
  handler && handler(payload);
1241
1325
  })
1242
1326
  );
1243
1327
  };
1244
1328
  var subscribeToGameEvents = (cxf) => {
1245
- cxf.on(import_cxf_events.CxfEvents.Login, (e) => {
1329
+ cxf.on(import_cxf_events2.CxfEvents.Login, (e) => {
1246
1330
  const { gameEvents: eventsInLogin, language, token, zoneId } = e;
1247
1331
  if (whitelistedZones.has(Number(zoneId)) && (Number(zoneId) > 300 || localStorage.getItem("cxf_canvas") === "enabled")) {
1248
1332
  globalState.updateStore({
@@ -1255,7 +1339,7 @@
1255
1339
  ...e,
1256
1340
  gameEvents: [...gameEvents.filter(eventNotExistPredicateGenerator(eventsInLogin)), ...eventsInLogin]
1257
1341
  });
1258
- log(import_cxf_events.CxfEvents.Login, globalState.getStore());
1342
+ log(import_cxf_events2.CxfEvents.Login, globalState.getStore());
1259
1343
  if (!isCanvas) {
1260
1344
  globalState.fetchUnreadOfferNotificationsCount();
1261
1345
  return;
@@ -1264,7 +1348,11 @@
1264
1348
  const { CANVAS_APP_ID_BY_GAME } = globalState.getConfig();
1265
1349
  const platform = detectPlatform();
1266
1350
  const canvasApps = CANVAS_APP_ID_BY_GAME[cxf.gameId];
1267
- const canvasAppId = typeof canvasApps === "string" ? canvasApps : canvasApps?.[platform];
1351
+ const canvasAppId = typeof canvasApps === "string" ? canvasApps : canvasApps[platform];
1352
+ if (!canvasAppId) {
1353
+ logError("Canvas app id not found for platform", { platform, canvasApps });
1354
+ return;
1355
+ }
1268
1356
  window.CanvasAgent.create({
1269
1357
  authClientId: "lemonstand",
1270
1358
  canvasAppId,
@@ -1273,14 +1361,14 @@
1273
1361
  token
1274
1362
  }).then((res) => {
1275
1363
  window.CanvasAgent.instance = res;
1276
- log(import_cxf_events.CxfEvents.Login, "Canvas created");
1364
+ log(import_cxf_events2.CxfEvents.Login, "Canvas created");
1277
1365
  }).catch((error) => {
1278
1366
  logError("Cannot create instance of Canvas", error);
1279
1367
  });
1280
1368
  }
1281
1369
  });
1282
- cxf.on(import_cxf_events.CxfEvents.GameEventUpdate, (e) => {
1283
- log(import_cxf_events.CxfEvents.GameEventUpdate, e);
1370
+ cxf.on(import_cxf_events2.CxfEvents.GameEventUpdate, (e) => {
1371
+ log(import_cxf_events2.CxfEvents.GameEventUpdate, e);
1284
1372
  const { gameEvents, isCanvas } = globalState.getStore();
1285
1373
  const updatedEventTypes = new Set(e.map((event) => event.type));
1286
1374
  globalState.updateStore({
@@ -1289,10 +1377,10 @@
1289
1377
  if (isCanvas) {
1290
1378
  window.CanvasAgent?.instance?.refresh();
1291
1379
  }
1292
- log(import_cxf_events.CxfEvents.GameEventUpdate, "reducer", globalState.getStore());
1380
+ log(import_cxf_events2.CxfEvents.GameEventUpdate, "reducer", globalState.getStore());
1293
1381
  });
1294
- cxf.on(import_cxf_events.CxfEvents.GameEventAdd, (e) => {
1295
- log(import_cxf_events.CxfEvents.GameEventAdd, e);
1382
+ cxf.on(import_cxf_events2.CxfEvents.GameEventAdd, (e) => {
1383
+ log(import_cxf_events2.CxfEvents.GameEventAdd, e);
1296
1384
  const { gameEvents, isCanvas } = globalState.getStore();
1297
1385
  globalState.updateStore({
1298
1386
  gameEvents: [...gameEvents, e]
@@ -1300,10 +1388,10 @@
1300
1388
  if (isCanvas) {
1301
1389
  window.CanvasAgent?.instance?.refresh();
1302
1390
  }
1303
- log(import_cxf_events.CxfEvents.GameEventAdd, "reducer", globalState.getStore());
1391
+ log(import_cxf_events2.CxfEvents.GameEventAdd, "reducer", globalState.getStore());
1304
1392
  });
1305
- cxf.on(import_cxf_events.CxfEvents.GameEventRemove, (e) => {
1306
- log(import_cxf_events.CxfEvents.GameEventRemove, e);
1393
+ cxf.on(import_cxf_events2.CxfEvents.GameEventRemove, (e) => {
1394
+ log(import_cxf_events2.CxfEvents.GameEventRemove, e);
1307
1395
  const { gameEvents, isCanvas } = globalState.getStore();
1308
1396
  globalState.updateStore({
1309
1397
  gameEvents: gameEvents.filter(({ type }) => type !== e)
@@ -1311,28 +1399,28 @@
1311
1399
  if (isCanvas) {
1312
1400
  window.CanvasAgent?.instance?.refresh();
1313
1401
  }
1314
- log(import_cxf_events.CxfEvents.GameEventRemove, "reducer", globalState.getStore());
1402
+ log(import_cxf_events2.CxfEvents.GameEventRemove, "reducer", globalState.getStore());
1315
1403
  });
1316
- cxf.on(import_cxf_events.CxfEvents.LevelChanged, (level) => {
1317
- log(import_cxf_events.CxfEvents.LevelChanged, level);
1404
+ cxf.on(import_cxf_events2.CxfEvents.LevelChanged, (level) => {
1405
+ log(import_cxf_events2.CxfEvents.LevelChanged, level);
1318
1406
  const { isCanvas } = globalState.getStore();
1319
1407
  globalState.updateStore({
1320
1408
  level
1321
1409
  });
1322
- log(import_cxf_events.CxfEvents.LevelChanged, "reducer", globalState.getStore());
1410
+ log(import_cxf_events2.CxfEvents.LevelChanged, "reducer", globalState.getStore());
1323
1411
  if (isCanvas) {
1324
1412
  window.CanvasAgent?.instance?.refresh();
1325
1413
  } else {
1326
1414
  globalState.fetchUnreadOfferNotificationsCount();
1327
1415
  }
1328
1416
  });
1329
- cxf.on(import_cxf_events.CxfEvents.LegendLevelChanged, (legendLevel) => {
1330
- log(import_cxf_events.CxfEvents.LegendLevelChanged, `legendLevel: ${legendLevel}`);
1417
+ cxf.on(import_cxf_events2.CxfEvents.LegendLevelChanged, (legendLevel) => {
1418
+ log(import_cxf_events2.CxfEvents.LegendLevelChanged, `legendLevel: ${legendLevel}`);
1331
1419
  globalState.updateStore({
1332
1420
  legendLevel
1333
1421
  });
1334
1422
  const store = globalState.getStore();
1335
- log(import_cxf_events.CxfEvents.LegendLevelChanged, "reducer", store);
1423
+ log(import_cxf_events2.CxfEvents.LegendLevelChanged, "reducer", store);
1336
1424
  globalState.fetchUnreadOfferNotificationsCount();
1337
1425
  });
1338
1426
  };
@@ -1444,43 +1532,6 @@
1444
1532
  log("App has started");
1445
1533
  };
1446
1534
 
1447
- // src/config.ts
1448
- init_define_process();
1449
- var import_cxf_events2 = __toESM(require_typings());
1450
- var COMMON_CONFIG = {
1451
- CANVAS_AGENT_URL: define_process_default.env.CANVAS_AGENT_URL,
1452
- CANVAS_APP_ID_BY_GAME: define_process_default.env.CANVAS_APP_ID_BY_GAME,
1453
- CUSTOMIZATION_URL: define_process_default.env.CUSTOMIZATION_URL,
1454
- CUSTOMIZATION_URL_TEMPLATE: define_process_default.env.CUSTOMIZATION_URL_TEMPLATE,
1455
- BASE_URL: define_process_default.env.BASE_URL,
1456
- CXF_DIALOG_OPEN: "cxf.dialog.open",
1457
- CXF_DIALOG_CLOSE: "cxf.dialog.close",
1458
- CXF_TRACK_MSG: "cxf.tracking.message",
1459
- CXF_BTN_CLICK_MSG: import_cxf_events2.CxfEvents.OpenIGS,
1460
- CXF_OPEN_SALES_MSG: "cxf.webshop.sales.open" /* CXF_OPEN_SALES_MSG */,
1461
- WEB_SHOP_CALL_TRACK_ID: 1181,
1462
- CXF_ERROR: "cxf.error",
1463
- CXF_PUSH: "cxf.push",
1464
- CXF_AD_STATUS: "cxf.adBanner.status"
1465
- };
1466
- var GAME_SPECIFIC_CONFIG = {
1467
- 12: {
1468
- LEGEND_LEVEL_IS_USED: true
1469
- },
1470
- 15: {
1471
- LEGEND_LEVEL_IS_USED: false
1472
- },
1473
- 16: {
1474
- LEGEND_LEVEL_IS_USED: true
1475
- }
1476
- };
1477
- var createConfig = (gameId) => {
1478
- return {
1479
- ...COMMON_CONFIG,
1480
- ...GAME_SPECIFIC_CONFIG[gameId]
1481
- };
1482
- };
1483
-
1484
1535
  // src/index.ts
1485
1536
  require_dist().then((cxf) => {
1486
1537
  const config = createConfig(cxf.gameId);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@goodgamestudios/cxf-webshop",
3
3
  "description": "WebShop CXF Module",
4
- "version": "7.1.0-qa.1",
4
+ "version": "7.1.0-qa.2",
5
5
  "keywords": [],
6
6
  "license": "UNLICENSED",
7
7
  "repository": {