@paypay/mini-app-js-sdk 2.46.0 → 2.48.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.
Files changed (33) hide show
  1. package/dist/client/clientUtils.d.ts +1 -1
  2. package/dist/client/communicationWithCore.d.ts +16 -0
  3. package/dist/client/functions/copyToClipboard.d.ts +2 -0
  4. package/dist/client/functions/coreWindowBridgeFunctions.d.ts +12 -0
  5. package/dist/client/functions/getKycPassportInfo.d.ts +3 -0
  6. package/dist/client/functions/logout.d.ts +6 -0
  7. package/dist/client/functions/renderCoupons.d.ts +6 -0
  8. package/dist/client/functions/scanCode.d.ts +2 -0
  9. package/dist/client/functions/setTitle.d.ts +2 -0
  10. package/dist/client/functions/share.d.ts +2 -0
  11. package/dist/client/functions/storageFunctions.d.ts +6 -0
  12. package/dist/client/functions/verifyMultiFactorAuthResult.d.ts +3 -0
  13. package/dist/client/index.d.ts +4 -59
  14. package/dist/client/types.d.ts +37 -2
  15. package/dist/client/{clientFunctions → windowBridgeFunctions}/storageFunctions.d.ts +10 -0
  16. package/dist/client/{clientFunctions → windowBridgeFunctions}/urlFunctions.d.ts +1 -0
  17. package/dist/core/coreFunctions/getLoginUrl.d.ts +1 -1
  18. package/dist/core/coreUtils.d.ts +1 -1
  19. package/dist/mini-app-js-sdk.browser.js +1 -1
  20. package/dist/mini-app-js-sdk.es.js +443 -557
  21. package/dist/model/bridge/getTopBarHeight.d.ts +1 -1
  22. package/dist/package/lottie/lottie.d.ts +6 -6
  23. package/dist/types/init.d.ts +0 -2
  24. package/dist/types/makePayment.d.ts +2 -1
  25. package/dist/utils/getAppDetail.d.ts +1 -0
  26. package/dist/utils/helper.d.ts +5 -2
  27. package/dist/views/coupon/components/Arrow/index.d.ts +5 -5
  28. package/dist/views/coupon/components/CouponAction/index.d.ts +4 -4
  29. package/dist/views/coupon/components/CouponContainer/index.d.ts +3 -3
  30. package/dist/views/coupon/index.d.ts +4 -4
  31. package/package.json +9 -9
  32. package/dist/types/getLoginUrl.d.ts +0 -8
  33. /package/dist/client/{clientFunctions → windowBridgeFunctions}/index.d.ts +0 -0
@@ -300,11 +300,6 @@ const smartPaymentSupportedFunctions = [
300
300
  "renderCoupons",
301
301
  "getLoginUrl"
302
302
  ];
303
- function url(path) {
304
- return "https://image.paypay.ne.jp/miniapps/mini-app-sdk/" + path;
305
- }
306
- const img_paypayRec = url("icon-paypay-rec.svg");
307
- const img_paypayRecWhite = url("icon-paypay-rec-white.svg");
308
303
  class PPError extends Error {
309
304
  constructor(message, errorCode) {
310
305
  super(message);
@@ -384,8 +379,8 @@ var MiniAppErrorType = /* @__PURE__ */ ((MiniAppErrorType2) => {
384
379
  MiniAppErrorType2["authorizationNeeded"] = "AUTHORIZATION_NEEDED";
385
380
  return MiniAppErrorType2;
386
381
  })(MiniAppErrorType || {});
387
- const JS_SDK_VERSION = "2.46.0";
388
- const REVISION = "bd28c67";
382
+ const JS_SDK_VERSION = "2.48.0";
383
+ const REVISION = "765ecbf";
389
384
  const coreBaseUrl = new URL("https://mini-app-sdk-core.paypay.ne.jp/");
390
385
  const CORE_IFRAME_ORIGIN = coreBaseUrl.origin;
391
386
  const CORE_IFRAME_URL = new URL(
@@ -1596,128 +1591,12 @@ class LocalStorageProxy {
1596
1591
  }
1597
1592
  }
1598
1593
  new LocalStorageProxy();
1594
+ function isFunction(val) {
1595
+ return typeof val === "function";
1596
+ }
1599
1597
  function getRandomString() {
1600
1598
  return Math.random().toString(36).substring(7);
1601
1599
  }
1602
- function checkIFrameOrigin(origin) {
1603
- return origin === CORE_IFRAME_ORIGIN;
1604
- }
1605
- function getIconUrl(theme) {
1606
- return theme === "red" ? img_paypayRecWhite : img_paypayRec;
1607
- }
1608
- function convertToString(str) {
1609
- return str ? String(str) : "";
1610
- }
1611
- function getRefreshToken(clientId) {
1612
- const refreshTokenWithClientId = api.get(
1613
- `${PpLocalStorageKey.refreshToken}.${clientId}`
1614
- );
1615
- return refreshTokenWithClientId || api.get(PpLocalStorageKey.refreshToken) || "";
1616
- }
1617
- function getCodeVerifier(clientId) {
1618
- return api.get(`${PpLocalStorageKey.codeVerifier}.${clientId}`) || api.get(PpLocalStorageKey.codeVerifier) || "";
1619
- }
1620
- function exposeClientJsBridge(jsBridge) {
1621
- if (window.hasOwnProperty(jsBridgeNamespace) && window[jsBridgeNamespace] === jsBridge) {
1622
- return false;
1623
- }
1624
- window[jsBridgeNamespace] = jsBridge;
1625
- return true;
1626
- }
1627
- function consoleDebugInfo(params) {
1628
- console.debug(...params);
1629
- }
1630
- function isSupportedMiniapp(functionName) {
1631
- return miniAppSupportedFunctions.includes(functionName);
1632
- }
1633
- function isSupportedSmartpayment(functionName) {
1634
- return smartPaymentSupportedFunctions.includes(
1635
- functionName
1636
- );
1637
- }
1638
- let runningFunctions = [];
1639
- function isFunctionRunning() {
1640
- return runningFunctions.length > 0;
1641
- }
1642
- function functionEnd(messageId) {
1643
- runningFunctions = runningFunctions.filter((val) => {
1644
- return val !== messageId;
1645
- });
1646
- }
1647
- function functionStart() {
1648
- const messageId = getRandomString();
1649
- runningFunctions.push(messageId);
1650
- return messageId;
1651
- }
1652
- function promiseToCallback(functionName, target, getCore2, getLoggingParams) {
1653
- return function(params = {}) {
1654
- const core2 = getCore2();
1655
- const loggingParams = getLoggingParams == null ? void 0 : getLoggingParams(params);
1656
- void core2.logEvent(__spreadValues({
1657
- event_action: `pp_${functionName}_called`,
1658
- event_category_suffix: functionName
1659
- }, loggingParams));
1660
- target(params).then((result) => {
1661
- var _a;
1662
- void core2.logEvent(__spreadValues({
1663
- event_action: `pp_${functionName}_success`,
1664
- event_category_suffix: functionName
1665
- }, loggingParams));
1666
- (_a = params.success) == null ? void 0 : _a.call(params, result);
1667
- }).catch((error) => {
1668
- var _a;
1669
- console.error(error.message);
1670
- void core2.logEvent(__spreadValues({
1671
- event_action: `pp_${functionName}_fail`,
1672
- event_category_suffix: functionName,
1673
- error_value: error.errorCode
1674
- }, loggingParams));
1675
- (_a = params.fail) == null ? void 0 : _a.call(params, { errorCode: error.errorCode });
1676
- }).finally(() => {
1677
- var _a;
1678
- (_a = params.complete) == null ? void 0 : _a.call(params);
1679
- });
1680
- };
1681
- }
1682
- const INIT_STATUS_CODE_REMAP = {
1683
- [MiniAppErrorType.sdkNotInitialized]: MiniAppErrorType.authorizationNeeded,
1684
- [MiniAppErrorType.tokenNotFound]: MiniAppErrorType.authorizationNeeded,
1685
- [MiniAppErrorType.tokenExpired]: MiniAppErrorType.tokenExpired
1686
- };
1687
- function callbackToPromise(target, functionName) {
1688
- return (params = {}) => {
1689
- return new Promise((resolve, reject) => {
1690
- target(__spreadProps(__spreadValues({}, params), {
1691
- success: (result) => {
1692
- var _a;
1693
- resolve(result);
1694
- (_a = params.success) == null ? void 0 : _a.call(params, result);
1695
- },
1696
- fail: (error) => {
1697
- var _a;
1698
- if (functionName === "init" && INIT_STATUS_CODE_REMAP[error.errorCode]) {
1699
- resolve({
1700
- statusCode: INIT_STATUS_CODE_REMAP[error.errorCode]
1701
- });
1702
- } else {
1703
- reject(error);
1704
- }
1705
- (_a = params.fail) == null ? void 0 : _a.call(params, error);
1706
- }
1707
- }));
1708
- });
1709
- };
1710
- }
1711
- var MiniAppStatusType = /* @__PURE__ */ ((MiniAppStatusType2) => {
1712
- MiniAppStatusType2["validToken"] = "TOKEN_VALID";
1713
- MiniAppStatusType2["initialized"] = "INITIALIZED";
1714
- MiniAppStatusType2["emailRegistered"] = "EMAIL_REGISTERED";
1715
- MiniAppStatusType2["emailNotVerified"] = "EMAIL_NOT_VERIFIED";
1716
- MiniAppStatusType2["success"] = "SUCCESS";
1717
- MiniAppStatusType2["loggedOut"] = "LOGGED_OUT";
1718
- MiniAppStatusType2["connected"] = "CONNECTED";
1719
- return MiniAppStatusType2;
1720
- })(MiniAppStatusType || {});
1721
1600
  function setCookie({ name, value, options }) {
1722
1601
  return api.set(name, value, options);
1723
1602
  }
@@ -1739,21 +1618,40 @@ function getLocalStorage({ name }) {
1739
1618
  function removeLocalStorage({ name }) {
1740
1619
  return localStorage.removeItem(name);
1741
1620
  }
1621
+ function setSessionStorage({
1622
+ name,
1623
+ value
1624
+ }) {
1625
+ return sessionStorage.setItem(name, value);
1626
+ }
1627
+ function getSessionStorage({ name }) {
1628
+ return sessionStorage.getItem(name);
1629
+ }
1630
+ function removeSessionStorage({ name }) {
1631
+ return sessionStorage.removeItem(name);
1632
+ }
1742
1633
  function removeQueryParametersFromUrl(removeParams) {
1743
- const url2 = new URL(window.location.href);
1744
- removeParams.forEach((param) => url2.searchParams.delete(param));
1745
- const newURL = `${url2.pathname}${url2.search}`;
1746
- history.replaceState(null, "", newURL);
1634
+ const url = new URL(window.location.href);
1635
+ removeParams.forEach((param) => url.searchParams.delete(param));
1636
+ const newURL = `${url.pathname}${url.search}`;
1637
+ history.replaceState(history.state, "", newURL);
1638
+ }
1639
+ function getUrl() {
1640
+ return window.location.href;
1747
1641
  }
1748
1642
  const clientWindowBridgeFunctions = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1749
1643
  __proto__: null,
1750
1644
  getCookie,
1751
1645
  getLocalStorage,
1646
+ getSessionStorage,
1647
+ getUrl,
1752
1648
  removeCookie,
1753
1649
  removeLocalStorage,
1754
1650
  removeQueryParametersFromUrl,
1651
+ removeSessionStorage,
1755
1652
  setCookie,
1756
- setLocalStorage
1653
+ setLocalStorage,
1654
+ setSessionStorage
1757
1655
  }, Symbol.toStringTag, { value: "Module" }));
1758
1656
  const IFRAME_NAME = "ppmna-iframe";
1759
1657
  const IFRAME_CONTAINER_NAME = "ppsdk-container";
@@ -1818,6 +1716,7 @@ function createIframe() {
1818
1716
  iframe.setAttribute("allow", "geolocation");
1819
1717
  iframe.onload = () => {
1820
1718
  resolve(iframe);
1719
+ iframe.onerror = null;
1821
1720
  };
1822
1721
  iframe.onerror = reject;
1823
1722
  iframe.style.all = "initial";
@@ -1832,180 +1731,409 @@ function createIframe() {
1832
1731
  }
1833
1732
  });
1834
1733
  }
1835
- let useAllFunctions = false;
1836
- let clientSdkType;
1837
- let initDonePromise;
1838
1734
  WindowBridge.init(clientWindowBridgeFunctions, [CORE_IFRAME_ORIGIN]);
1839
- void getCoreIframe();
1840
- function clearInternalInitSyncState() {
1841
- initDonePromise = Promise.resolve(false);
1842
- }
1843
- clearInternalInitSyncState();
1844
- const core = WindowBridge.getTargetWindowFunctionProxy(
1735
+ const coreFunctions = WindowBridge.getTargetWindowFunctionProxy(
1845
1736
  getCoreIframeWindow,
1846
1737
  CORE_IFRAME_ORIGIN
1847
1738
  );
1848
- function getCore() {
1849
- return core;
1850
- }
1851
- const commonMessageHandler = (e) => {
1852
- var _a;
1853
- if ((_a = e.data) == null ? void 0 : _a.forWindowBridge) {
1854
- return;
1855
- }
1856
- if (!checkIFrameOrigin(e.origin)) {
1857
- return;
1858
- }
1859
- if (e.data.name === PPUtilFunctionName.reload) {
1860
- window.location.reload();
1739
+ function receiveMessageFromIframe(messageData, params, eventHandler) {
1740
+ var _a, _b, _c;
1741
+ if (messageData.result === PPFunctionResult.fail) {
1742
+ (_a = params == null ? void 0 : params.fail) == null ? void 0 : _a.call(params, messageData.data);
1861
1743
  }
1862
- if (e.data.name === PPUtilFunctionName.makeVisible) {
1863
- showCoreIframe(true);
1864
- return;
1744
+ if (messageData.result === PPFunctionResult.success) {
1745
+ (_b = params == null ? void 0 : params.success) == null ? void 0 : _b.call(params, messageData == null ? void 0 : messageData.data);
1865
1746
  }
1866
- if (e.data.name === PPUtilFunctionName.link) {
1867
- const linkOption = e.data.data;
1868
- if (linkOption.target === "_blank") {
1869
- window.open(linkOption.url, "_blank");
1870
- } else {
1871
- window.location.href = linkOption.url;
1747
+ if (messageData.result === PPFunctionResult.complete) {
1748
+ (_c = params == null ? void 0 : params.complete) == null ? void 0 : _c.call(params);
1749
+ removeEventListener("message", eventHandler);
1750
+ functionEnd(messageData.messageId);
1751
+ if (!isFunctionRunning()) {
1752
+ showCoreIframe(false);
1872
1753
  }
1873
1754
  }
1874
- if (e.data.name === PPUtilFunctionName.consoleDebugInfo) {
1875
- const { params } = e.data.data;
1876
- consoleDebugInfo(params);
1877
- }
1878
- };
1879
- addEventListener("message", commonMessageHandler);
1880
- addEventListener("popstate", () => {
1881
- getCoreIframe().then((iframe) => {
1882
- var _a;
1883
- const data = {
1884
- name: PPUtilFunctionName.clientPopState
1885
- };
1886
- (_a = iframe == null ? void 0 : iframe.contentWindow) == null ? void 0 : _a.postMessage(data, CORE_IFRAME_ORIGIN);
1887
- }).catch((error) => console.warn(error));
1888
- });
1889
- function init(params) {
1890
- const refreshToken = getRefreshToken(params.clientId);
1891
- const codeVerifier = getCodeVerifier(params.clientId);
1892
- const clientVersion = "2.46.0";
1893
- useAllFunctions = !!params.useAllFunctions;
1894
- const initParams = {
1895
- env: params.env,
1896
- mode: params.mode,
1897
- debugMode: params.debugMode,
1898
- clientId: params.clientId,
1899
- refreshToken,
1900
- clientVersion,
1901
- codeVerifier,
1902
- clientSdkType,
1903
- clientUrl: window.location.href
1904
- };
1905
- let initDonePromiseResolve;
1906
- const nextInitDonePromise = new Promise(
1907
- (resolve) => initDonePromiseResolve = resolve
1908
- );
1909
- const complete = () => {
1755
+ }
1756
+ function postMessageToCore(messageData) {
1757
+ return __async(this, null, function* () {
1910
1758
  var _a;
1911
- initDonePromiseResolve(true);
1912
- (_a = params.complete) == null ? void 0 : _a.call(params);
1913
- };
1914
- initDonePromise.then(() => getCoreIframe()).then(() => {
1915
- triggerPostMessageToCore(
1916
- PPFunctionName.init,
1917
- false,
1918
- __spreadProps(__spreadValues({}, params), { complete }),
1919
- initParams
1759
+ const iframe = yield getCoreIframe().catch(() => void 0);
1760
+ (_a = iframe == null ? void 0 : iframe.contentWindow) == null ? void 0 : _a.postMessage(
1761
+ JSON.parse(JSON.stringify(messageData)),
1762
+ CORE_IFRAME_ORIGIN
1920
1763
  );
1921
- }).catch(() => {
1922
- var _a;
1923
- (_a = params.fail) == null ? void 0 : _a.call(params, { errorCode: MiniAppErrorType.sdkNotInitialized });
1924
- complete();
1925
1764
  });
1926
- initDonePromise = nextInitDonePromise;
1927
1765
  }
1928
- function verifyMultiFactorAuthResult(params) {
1929
- const url2 = new URL(window.location.href);
1930
- triggerPostMessageToCore(
1931
- PPFunctionName.verifyMultiFactorAuthResult,
1932
- false,
1933
- params,
1934
- __spreadProps(__spreadValues({}, params), { sessionId: url2.searchParams.get("ppSessionId") })
1766
+ function triggerPostMessageToCore(type, showIframeFlag, params, postMessageParams) {
1767
+ const messageId = functionStart();
1768
+ const fnMessageHandler = (e) => {
1769
+ if (!checkIFrameOrigin(e.origin)) {
1770
+ return;
1771
+ }
1772
+ if (e.data.name === type) {
1773
+ if (e.data.messageId === messageId) {
1774
+ receiveMessageFromIframe(e.data, params, fnMessageHandler);
1775
+ }
1776
+ }
1777
+ };
1778
+ addEventListener("message", fnMessageHandler);
1779
+ void postMessageToCore({
1780
+ name: type,
1781
+ params: postMessageParams,
1782
+ messageId
1783
+ });
1784
+ }
1785
+ function checkIFrameOrigin(origin) {
1786
+ return origin === CORE_IFRAME_ORIGIN;
1787
+ }
1788
+ function getRefreshToken(clientId) {
1789
+ const refreshTokenWithClientId = api.get(
1790
+ `${PpLocalStorageKey.refreshToken}.${clientId}`
1935
1791
  );
1792
+ return refreshTokenWithClientId || api.get(PpLocalStorageKey.refreshToken) || "";
1936
1793
  }
1937
- function getKycPassportInfo(params) {
1938
- const url2 = window.location.href;
1939
- triggerPostMessageToCore(PPFunctionName.getKycPassportInfo, false, params, __spreadProps(__spreadValues({}, params), {
1940
- url: url2
1941
- }));
1794
+ function getCodeVerifier(clientId) {
1795
+ return api.get(`${PpLocalStorageKey.codeVerifier}.${clientId}`) || api.get(PpLocalStorageKey.codeVerifier) || "";
1942
1796
  }
1943
- function share(params) {
1944
- if (!(navigator == null ? void 0 : navigator.share)) {
1945
- triggerPostMessageToCore(PPFunctionName.share, false, params, params);
1946
- return;
1797
+ function exposeClientJsBridge(jsBridge) {
1798
+ if (window.hasOwnProperty(jsBridgeNamespace) && window[jsBridgeNamespace] === jsBridge) {
1799
+ return false;
1947
1800
  }
1948
- const data = {
1949
- //url: params.imageUrl,
1950
- //TODO: -> we need to download the imageUrl and try to attach it to `files`
1951
- text: params == null ? void 0 : params.text
1801
+ window[jsBridgeNamespace] = jsBridge;
1802
+ return true;
1803
+ }
1804
+ function consoleDebugInfo(params) {
1805
+ console.debug(...params);
1806
+ }
1807
+ function isSupportedMiniapp(functionName) {
1808
+ return miniAppSupportedFunctions.includes(functionName);
1809
+ }
1810
+ function isSupportedSmartpayment(functionName) {
1811
+ return smartPaymentSupportedFunctions.includes(
1812
+ functionName
1813
+ );
1814
+ }
1815
+ let runningFunctions = [];
1816
+ function isFunctionRunning() {
1817
+ return runningFunctions.length > 0;
1818
+ }
1819
+ function functionEnd(messageId) {
1820
+ runningFunctions = runningFunctions.filter((val) => {
1821
+ return val !== messageId;
1822
+ });
1823
+ }
1824
+ function functionStart() {
1825
+ const messageId = getRandomString();
1826
+ runningFunctions.push(messageId);
1827
+ return messageId;
1828
+ }
1829
+ function promiseToCallback(functionName, target, getLoggingParams) {
1830
+ return function(params = {}) {
1831
+ const loggingParams = getLoggingParams == null ? void 0 : getLoggingParams(params);
1832
+ void coreFunctions.logEvent(__spreadValues({
1833
+ event_action: `pp_${functionName}_called`,
1834
+ event_category_suffix: functionName
1835
+ }, loggingParams));
1836
+ const resultPromise = target(params);
1837
+ resultPromise.then((result) => {
1838
+ var _a;
1839
+ void coreFunctions.logEvent(__spreadValues({
1840
+ event_action: `pp_${functionName}_success`,
1841
+ event_category_suffix: functionName
1842
+ }, loggingParams));
1843
+ (_a = params.success) == null ? void 0 : _a.call(params, result);
1844
+ }).catch((error) => {
1845
+ var _a;
1846
+ console.error(error.message);
1847
+ void coreFunctions.logEvent(__spreadValues({
1848
+ event_action: `pp_${functionName}_fail`,
1849
+ event_category_suffix: functionName,
1850
+ error_value: error.errorCode
1851
+ }, loggingParams));
1852
+ (_a = params.fail) == null ? void 0 : _a.call(params, { errorCode: error.errorCode });
1853
+ }).finally(() => {
1854
+ var _a;
1855
+ (_a = params.complete) == null ? void 0 : _a.call(params);
1856
+ });
1857
+ return resultPromise;
1952
1858
  };
1953
- navigator.share(data).then(() => {
1954
- var _a, _b;
1955
- (_a = params == null ? void 0 : params.success) == null ? void 0 : _a.call(params);
1956
- (_b = params == null ? void 0 : params.complete) == null ? void 0 : _b.call(params);
1859
+ }
1860
+ const INIT_STATUS_CODE_REMAP = {
1861
+ [MiniAppErrorType.sdkNotInitialized]: MiniAppErrorType.authorizationNeeded,
1862
+ [MiniAppErrorType.tokenNotFound]: MiniAppErrorType.authorizationNeeded,
1863
+ [MiniAppErrorType.tokenExpired]: MiniAppErrorType.tokenExpired
1864
+ };
1865
+ function callbackToPromise(target, functionName) {
1866
+ return (params = {}) => {
1867
+ return new Promise((resolve, reject) => {
1868
+ target(__spreadProps(__spreadValues({}, params), {
1869
+ success: (result) => {
1870
+ var _a;
1871
+ resolve(result);
1872
+ (_a = params.success) == null ? void 0 : _a.call(params, result);
1873
+ },
1874
+ fail: (error) => {
1875
+ var _a;
1876
+ if (functionName === "init" && INIT_STATUS_CODE_REMAP[error.errorCode]) {
1877
+ resolve({
1878
+ statusCode: INIT_STATUS_CODE_REMAP[error.errorCode]
1879
+ });
1880
+ } else {
1881
+ reject(error);
1882
+ }
1883
+ (_a = params.fail) == null ? void 0 : _a.call(params, error);
1884
+ }
1885
+ }));
1886
+ });
1887
+ };
1888
+ }
1889
+ let clientSdkType;
1890
+ let initDonePromise;
1891
+ void getCoreIframe();
1892
+ function clearInternalInitSyncState() {
1893
+ initDonePromise = Promise.resolve(false);
1894
+ }
1895
+ clearInternalInitSyncState();
1896
+ const commonMessageHandler = (e) => {
1897
+ var _a;
1898
+ if ((_a = e.data) == null ? void 0 : _a.forWindowBridge) {
1899
+ return;
1900
+ }
1901
+ if (!checkIFrameOrigin(e.origin)) {
1902
+ return;
1903
+ }
1904
+ if (e.data.name === PPUtilFunctionName.reload) {
1905
+ window.location.reload();
1906
+ }
1907
+ if (e.data.name === PPUtilFunctionName.makeVisible) {
1908
+ showCoreIframe(true);
1909
+ return;
1910
+ }
1911
+ if (e.data.name === PPUtilFunctionName.link) {
1912
+ const linkOption = e.data.data;
1913
+ if (linkOption.target === "_blank") {
1914
+ window.open(linkOption.url, "_blank");
1915
+ } else {
1916
+ window.location.href = linkOption.url;
1917
+ }
1918
+ }
1919
+ if (e.data.name === PPUtilFunctionName.consoleDebugInfo) {
1920
+ const { params } = e.data.data;
1921
+ consoleDebugInfo(params);
1922
+ }
1923
+ };
1924
+ addEventListener("message", commonMessageHandler);
1925
+ addEventListener("popstate", () => {
1926
+ getCoreIframe().then((iframe) => {
1927
+ var _a;
1928
+ const data = {
1929
+ name: PPUtilFunctionName.clientPopState
1930
+ };
1931
+ (_a = iframe == null ? void 0 : iframe.contentWindow) == null ? void 0 : _a.postMessage(data, CORE_IFRAME_ORIGIN);
1932
+ }).catch((error) => console.warn(error));
1933
+ });
1934
+ function init(params) {
1935
+ const refreshToken = getRefreshToken(params.clientId);
1936
+ const codeVerifier = getCodeVerifier(params.clientId);
1937
+ const clientVersion = "2.48.0";
1938
+ const initParams = {
1939
+ env: params.env,
1940
+ mode: params.mode,
1941
+ debugMode: params.debugMode,
1942
+ clientId: params.clientId,
1943
+ refreshToken,
1944
+ clientVersion,
1945
+ codeVerifier,
1946
+ clientSdkType,
1947
+ clientUrl: window.location.href
1948
+ };
1949
+ let initDonePromiseResolve;
1950
+ const nextInitDonePromise = new Promise(
1951
+ (resolve) => initDonePromiseResolve = resolve
1952
+ );
1953
+ const complete = () => {
1954
+ var _a;
1955
+ initDonePromiseResolve(true);
1956
+ (_a = params.complete) == null ? void 0 : _a.call(params);
1957
+ };
1958
+ initDonePromise.then(() => getCoreIframe()).then(() => {
1959
+ triggerPostMessageToCore(
1960
+ PPFunctionName.init,
1961
+ false,
1962
+ __spreadProps(__spreadValues({}, params), { complete }),
1963
+ initParams
1964
+ );
1957
1965
  }).catch(() => {
1958
- var _a, _b;
1959
- (_a = params == null ? void 0 : params.fail) == null ? void 0 : _a.call(params, { errorCode: MiniAppErrorType.unknown });
1960
- (_b = params == null ? void 0 : params.complete) == null ? void 0 : _b.call(params);
1966
+ var _a;
1967
+ (_a = params.fail) == null ? void 0 : _a.call(params, { errorCode: MiniAppErrorType.sdkNotInitialized });
1968
+ complete();
1961
1969
  });
1970
+ initDonePromise = nextInitDonePromise;
1962
1971
  }
1963
- function setTitle(params) {
1964
- var _a, _b;
1965
- document.title = (params == null ? void 0 : params.title) || "";
1966
- (_a = params == null ? void 0 : params.success) == null ? void 0 : _a.call(params);
1967
- (_b = params == null ? void 0 : params.complete) == null ? void 0 : _b.call(params);
1968
- }
1969
- function render(params) {
1970
- var _a, _b;
1971
- if (!params.containerId || !document.getElementById(params.containerId)) {
1972
- (_a = params.fail) == null ? void 0 : _a.call(params, {
1973
- errorCode: MiniAppErrorType.badRequestInsufficientParameter
1972
+ const clientJsBridge = {
1973
+ _handleMessageFromNative: (json) => {
1974
+ void getCoreIframe().then((iframe) => {
1975
+ var _a;
1976
+ (_a = iframe == null ? void 0 : iframe.contentWindow) == null ? void 0 : _a.postMessage(
1977
+ JSON.parse(
1978
+ JSON.stringify({
1979
+ name: PPFunctionName.handleMessageFromNative,
1980
+ params: {
1981
+ json
1982
+ }
1983
+ })
1984
+ ),
1985
+ CORE_IFRAME_ORIGIN
1986
+ );
1974
1987
  });
1975
- (_b = params.complete) == null ? void 0 : _b.call(params);
1976
- return console.error("Invalid container Id");
1977
1988
  }
1978
- const messageId = functionStart();
1979
- const getRenderMessageHandler = (e) => {
1980
- var _a2, _b2, _c;
1981
- if (!checkIFrameOrigin(e.origin) || e.data.name !== PPFunctionName.render || e.data.messageId !== messageId) {
1982
- return;
1989
+ };
1990
+ exposeClientJsBridge(clientJsBridge);
1991
+ const initExemptedFunctions = [
1992
+ "init",
1993
+ "setTitle",
1994
+ "copyToClipboard",
1995
+ "getSessionData",
1996
+ "setSessionData",
1997
+ "getStorageData",
1998
+ "setStorageData",
1999
+ "removeStorageData",
2000
+ "getLoginUrl"
2001
+ ];
2002
+ const autoInitFunctions = ["renderCoupons"];
2003
+ function executePendingFunctionCalls(client2) {
2004
+ const pendingFunctionCalls = window._ppcs;
2005
+ if (!pendingFunctionCalls) {
2006
+ return;
2007
+ }
2008
+ window._ppcs = void 0;
2009
+ for (const [functionName, params, resolve] of pendingFunctionCalls) {
2010
+ const resultPromise = client2[functionName](params);
2011
+ if (resolve) {
2012
+ resolve(resultPromise);
1983
2013
  }
1984
- const info = (_a2 = e.data) == null ? void 0 : _a2.data;
1985
- const data = (_b2 = e.data) == null ? void 0 : _b2.data;
1986
- if (e.data.result === PPFunctionResult.success) {
1987
- renderButton(data, params);
1988
- if (info.type === "pay" && (data == null ? void 0 : data.isJustLoggedIn) && params.autoInvoke && (data == null ? void 0 : data.isLoggedIn)) {
1989
- triggerPostMessageToCore(PPFunctionName.makePayment, true, params, __spreadValues({}, params.orderInfo));
2014
+ }
2015
+ }
2016
+ const clientProperties = {
2017
+ version: "2.48.0",
2018
+ revision: "765ecbf"
2019
+ };
2020
+ function isInitClientParams(params) {
2021
+ return params.clientId !== void 0;
2022
+ }
2023
+ function getClient({
2024
+ sdkType,
2025
+ clientFunctions: clientFunctions2
2026
+ }) {
2027
+ clientSdkType = sdkType;
2028
+ const isSupportedFunction = sdkType === SdkType.MiniApp ? isSupportedMiniapp : isSupportedSmartpayment;
2029
+ const client2 = new Proxy(
2030
+ __spreadProps(__spreadValues({}, clientFunctions2), { init }),
2031
+ {
2032
+ get(target, prop) {
2033
+ if (prop in clientProperties) {
2034
+ return clientProperties[prop];
2035
+ }
2036
+ const functionName = prop;
2037
+ if (!isSupportedFunction(functionName)) {
2038
+ throw new Error(
2039
+ `${functionName} is not supported by ${sdkType} JS SDK`
2040
+ );
2041
+ }
2042
+ function callSdkFunction(params) {
2043
+ return __async(this, null, function* () {
2044
+ var _a, _b;
2045
+ if (!initExemptedFunctions.includes(functionName) && !(yield initDonePromise)) {
2046
+ if (autoInitFunctions.includes(functionName) && isInitClientParams(params)) {
2047
+ init({
2048
+ clientId: params.clientId,
2049
+ env: params.env
2050
+ });
2051
+ yield initDonePromise;
2052
+ } else {
2053
+ (_a = params.fail) == null ? void 0 : _a.call(params, {
2054
+ errorCode: MiniAppErrorType.sdkNotInitialized
2055
+ });
2056
+ (_b = params.complete) == null ? void 0 : _b.call(params);
2057
+ return;
2058
+ }
2059
+ }
2060
+ const fn = target[functionName];
2061
+ if (fn && isFunction(fn)) {
2062
+ return fn(params);
2063
+ }
2064
+ triggerPostMessageToCore(
2065
+ prop,
2066
+ false,
2067
+ params,
2068
+ params
2069
+ );
2070
+ });
2071
+ }
2072
+ return callbackToPromise(callSdkFunction, functionName);
1990
2073
  }
1991
2074
  }
1992
- if (e.data.result === PPFunctionResult.fail) {
1993
- (_c = params == null ? void 0 : params.fail) == null ? void 0 : _c.call(params, e.data.data);
1994
- }
1995
- if (e.data.result === PPFunctionResult.complete) {
1996
- functionEnd(e.data.messageId);
1997
- removeEventListener("message", getRenderMessageHandler);
1998
- }
1999
- };
2000
- addEventListener("message", getRenderMessageHandler);
2001
- void postMessageToCore({
2002
- name: PPFunctionName.render,
2003
- params: __spreadProps(__spreadValues({}, params), {
2004
- redirectUrl: params.redirectUrl || window.location.href
2005
- }),
2006
- messageId
2007
- });
2075
+ );
2076
+ window._pp = client2;
2077
+ executePendingFunctionCalls(client2);
2078
+ return client2;
2008
2079
  }
2080
+ function copyToClipboard(params) {
2081
+ var _a, _b, _c;
2082
+ const textarea = document.createElement("textarea");
2083
+ textarea.setAttribute("readonly", "true");
2084
+ textarea.setAttribute("contenteditable", "true");
2085
+ textarea.value = params.value;
2086
+ document.body.appendChild(textarea);
2087
+ textarea.select();
2088
+ textarea.setSelectionRange(0, textarea.value.length);
2089
+ const result = document.execCommand("copy");
2090
+ document.body.removeChild(textarea);
2091
+ if (result) {
2092
+ (_a = params == null ? void 0 : params.success) == null ? void 0 : _a.call(params);
2093
+ } else {
2094
+ (_b = params == null ? void 0 : params.fail) == null ? void 0 : _b.call(params, { errorCode: MiniAppErrorType.other });
2095
+ }
2096
+ (_c = params.complete) == null ? void 0 : _c.call(params);
2097
+ }
2098
+ promiseToCallback(
2099
+ "getLoginUrl",
2100
+ coreFunctions.getLoginUrl
2101
+ );
2102
+ const getPaymentSettings = promiseToCallback(
2103
+ "getPaymentSettings",
2104
+ coreFunctions.getPaymentSettings
2105
+ );
2106
+ const markAsReady = promiseToCallback(
2107
+ "markAsReady",
2108
+ coreFunctions.markAsReady
2109
+ );
2110
+ function getKycPassportInfo(params) {
2111
+ const url = window.location.href;
2112
+ triggerPostMessageToCore(PPFunctionName.getKycPassportInfo, false, params, __spreadProps(__spreadValues({}, params), {
2113
+ url
2114
+ }));
2115
+ }
2116
+ var MiniAppStatusType = /* @__PURE__ */ ((MiniAppStatusType2) => {
2117
+ MiniAppStatusType2["validToken"] = "TOKEN_VALID";
2118
+ MiniAppStatusType2["initialized"] = "INITIALIZED";
2119
+ MiniAppStatusType2["emailRegistered"] = "EMAIL_REGISTERED";
2120
+ MiniAppStatusType2["emailNotVerified"] = "EMAIL_NOT_VERIFIED";
2121
+ MiniAppStatusType2["success"] = "SUCCESS";
2122
+ MiniAppStatusType2["loggedOut"] = "LOGGED_OUT";
2123
+ MiniAppStatusType2["connected"] = "CONNECTED";
2124
+ return MiniAppStatusType2;
2125
+ })(MiniAppStatusType || {});
2126
+ const logout = promiseToCallback("logout", () => __async(void 0, null, function* () {
2127
+ try {
2128
+ yield coreFunctions.logout();
2129
+ return { statusCode: MiniAppStatusType.loggedOut };
2130
+ } catch (error) {
2131
+ throw new PPError(
2132
+ `An error ocurred while trying to logout the user, error=${error}`,
2133
+ MiniAppErrorType.unknown
2134
+ );
2135
+ }
2136
+ }));
2009
2137
  const renderCoupons = promiseToCallback(
2010
2138
  "renderCoupons",
2011
2139
  (params) => __async(void 0, null, function* () {
@@ -2024,7 +2152,7 @@ const renderCoupons = promiseToCallback(
2024
2152
  MiniAppErrorType.badRequestInsufficientParameter
2025
2153
  );
2026
2154
  }
2027
- const coupons = yield core.fetchCoupons({
2155
+ const coupons = yield coreFunctions.fetchCoupons({
2028
2156
  merchantId,
2029
2157
  couponId,
2030
2158
  postLoginRedirectUrl,
@@ -2068,7 +2196,6 @@ const renderCoupons = promiseToCallback(
2068
2196
  );
2069
2197
  }
2070
2198
  }),
2071
- getCore,
2072
2199
  (params) => ({
2073
2200
  event_label2: params.couponId,
2074
2201
  merchant_id: params.merchant
@@ -2086,6 +2213,32 @@ function scanCode(params) {
2086
2213
  scanCodeParams
2087
2214
  );
2088
2215
  }
2216
+ function setTitle(params) {
2217
+ var _a, _b, _c;
2218
+ document.title = (_a = params == null ? void 0 : params.title) != null ? _a : "";
2219
+ (_b = params == null ? void 0 : params.success) == null ? void 0 : _b.call(params);
2220
+ (_c = params == null ? void 0 : params.complete) == null ? void 0 : _c.call(params);
2221
+ }
2222
+ function share(params) {
2223
+ if (!(navigator == null ? void 0 : navigator.share)) {
2224
+ triggerPostMessageToCore(PPFunctionName.share, false, params, params);
2225
+ return;
2226
+ }
2227
+ const data = {
2228
+ //url: params.imageUrl,
2229
+ //TODO: -> we need to download the imageUrl and try to attach it to `files`
2230
+ text: params == null ? void 0 : params.text
2231
+ };
2232
+ navigator.share(data).then(() => {
2233
+ var _a, _b;
2234
+ (_a = params == null ? void 0 : params.success) == null ? void 0 : _a.call(params);
2235
+ (_b = params == null ? void 0 : params.complete) == null ? void 0 : _b.call(params);
2236
+ }).catch(() => {
2237
+ var _a, _b;
2238
+ (_a = params == null ? void 0 : params.fail) == null ? void 0 : _a.call(params, { errorCode: MiniAppErrorType.unknown });
2239
+ (_b = params == null ? void 0 : params.complete) == null ? void 0 : _b.call(params);
2240
+ });
2241
+ }
2089
2242
  function getSessionData(params) {
2090
2243
  var _a, _b;
2091
2244
  const value = sessionStorage.getItem(params == null ? void 0 : params.key);
@@ -2116,200 +2269,19 @@ function removeStorageData(params) {
2116
2269
  (_a = params == null ? void 0 : params.success) == null ? void 0 : _a.call(params);
2117
2270
  (_b = params == null ? void 0 : params.complete) == null ? void 0 : _b.call(params);
2118
2271
  }
2119
- const logout = promiseToCallback(
2120
- "logout",
2121
- () => __async(void 0, null, function* () {
2122
- try {
2123
- yield core.logout();
2124
- return { statusCode: MiniAppStatusType.loggedOut };
2125
- } catch (error) {
2126
- throw new PPError(
2127
- `An error ocurred while trying to logout the user, error=${error}`,
2128
- MiniAppErrorType.unknown
2129
- );
2130
- }
2131
- }),
2132
- getCore
2133
- );
2134
- const getPaymentSettings = promiseToCallback(
2135
- "getPaymentSettings",
2136
- core.getPaymentSettings,
2137
- getCore
2138
- );
2139
- const getLoginUrl = promiseToCallback(
2140
- "getLoginUrl",
2141
- (params) => {
2142
- return core.getLoginUrl({
2143
- redirectUrl: params.redirectUrl || location.href,
2144
- redirectType: params.redirectType
2145
- });
2146
- },
2147
- getCore
2148
- );
2149
- function copyToClipboard(params) {
2150
- var _a, _b, _c;
2151
- const textarea = document.createElement("textarea");
2152
- textarea.setAttribute("readonly", "true");
2153
- textarea.setAttribute("contenteditable", "true");
2154
- textarea.value = params.value;
2155
- document.body.appendChild(textarea);
2156
- textarea.select();
2157
- textarea.setSelectionRange(0, textarea.value.length);
2158
- const result = document.execCommand("copy");
2159
- document.body.removeChild(textarea);
2160
- if (result) {
2161
- (_a = params == null ? void 0 : params.success) == null ? void 0 : _a.call(params);
2162
- } else {
2163
- (_b = params == null ? void 0 : params.fail) == null ? void 0 : _b.call(params, { errorCode: MiniAppErrorType.other });
2164
- }
2165
- (_c = params.complete) == null ? void 0 : _c.call(params);
2166
- }
2167
- function receiveMessageFromIframe(messageData, params, eventHandler) {
2168
- var _a, _b, _c;
2169
- if (messageData.result === PPFunctionResult.fail) {
2170
- (_a = params == null ? void 0 : params.fail) == null ? void 0 : _a.call(params, messageData.data);
2171
- }
2172
- if (messageData.result === PPFunctionResult.success) {
2173
- (_b = params == null ? void 0 : params.success) == null ? void 0 : _b.call(params, messageData == null ? void 0 : messageData.data);
2174
- }
2175
- if (messageData.result === PPFunctionResult.complete) {
2176
- (_c = params == null ? void 0 : params.complete) == null ? void 0 : _c.call(params);
2177
- removeEventListener("message", eventHandler);
2178
- functionEnd(messageData.messageId);
2179
- if (!isFunctionRunning()) {
2180
- showCoreIframe(false);
2181
- }
2182
- }
2183
- }
2184
- function postMessageToCore(messageData) {
2185
- return __async(this, null, function* () {
2186
- var _a;
2187
- const iframe = yield getCoreIframe().catch(() => void 0);
2188
- (_a = iframe == null ? void 0 : iframe.contentWindow) == null ? void 0 : _a.postMessage(
2189
- JSON.parse(JSON.stringify(messageData)),
2190
- CORE_IFRAME_ORIGIN
2191
- );
2192
- });
2193
- }
2194
- function triggerPostMessageToCore(type, showIframeFlag, params, postMessageParams) {
2195
- const messageId = functionStart();
2196
- if (showIframeFlag) {
2197
- showCoreIframe(true);
2198
- }
2199
- const fnMessageHandler = (e) => {
2200
- if (!checkIFrameOrigin(e.origin)) {
2201
- return;
2202
- }
2203
- if (e.data.name === type) {
2204
- if (e.data.messageId === messageId) {
2205
- receiveMessageFromIframe(e.data, params, fnMessageHandler);
2206
- }
2207
- }
2208
- };
2209
- addEventListener("message", fnMessageHandler);
2210
- void postMessageToCore({
2211
- name: type,
2212
- params: postMessageParams,
2213
- messageId
2214
- });
2215
- }
2216
- function renderButton(data, params) {
2217
- var _a, _b, _c, _d, _e, _f, _g;
2218
- const container = document.getElementById(params.containerId);
2219
- const button = document.createElement("button");
2220
- button.className = "ppmna-reset-css pp-smartButtonWrapper pp-button";
2221
- const iconUrl = getIconUrl(params == null ? void 0 : params.theme);
2222
- const cashbackClass = ((_b = (_a = data == null ? void 0 : data.data) == null ? void 0 : _a.cashbackInfo) == null ? void 0 : _b.length) ? "pp-cashback" : "";
2223
- const shortTextClass = params.isShortText ? "pp-shortText" : "";
2224
- const buttonSize = (_c = params == null ? void 0 : params.buttonSize) != null ? _c : "lg";
2225
- const theme = (_d = params == null ? void 0 : params.theme) != null ? _d : "light";
2226
- const aTag = document.createElement("a");
2227
- aTag.className = `pp-smartBtn pp-${theme} pp-${buttonSize} pp-${convertToString(
2228
- params.type
2229
- )} pp-${data.preferredLanguage} ${cashbackClass} ${shortTextClass}`;
2230
- aTag.href = convertToString(data.data.loginUrl);
2231
- const leftSpan = document.createElement("span");
2232
- leftSpan.className = "pp-leftSection";
2233
- const iconImg = document.createElement("img");
2234
- iconImg.className = "pp-img";
2235
- iconImg.src = iconUrl;
2236
- iconImg.alt = "";
2237
- leftSpan.appendChild(iconImg);
2238
- const btnSpan = document.createElement("span");
2239
- btnSpan.className = "pp-btnContent";
2240
- const titleSpan = document.createElement("span");
2241
- titleSpan.className = "pp-title";
2242
- titleSpan.innerText = (_e = data == null ? void 0 : data.data) == null ? void 0 : _e.title;
2243
- btnSpan.appendChild(titleSpan);
2244
- leftSpan.appendChild(btnSpan);
2245
- aTag.append(leftSpan);
2246
- const cashbackSpan = document.createElement("span");
2247
- if ((_f = data == null ? void 0 : data.data) == null ? void 0 : _f.cashbackInfo) {
2248
- cashbackSpan.className = "pp-cashbackInfo";
2249
- cashbackSpan.innerText = (_g = data == null ? void 0 : data.data) == null ? void 0 : _g.cashbackInfo;
2250
- btnSpan.append(cashbackSpan);
2251
- }
2252
- if (data.data.avatarUrl) {
2253
- const avatarImg = document.createElement("img");
2254
- avatarImg.className = "pp-userProfile";
2255
- avatarImg.src = data.data.avatarUrl;
2256
- avatarImg.addEventListener("error", function(e) {
2257
- var _a2;
2258
- const el = e.target;
2259
- (_a2 = el == null ? void 0 : el.parentNode) == null ? void 0 : _a2.removeChild(el);
2260
- });
2261
- aTag.append(avatarImg);
2262
- }
2263
- button.append(aTag);
2264
- if (container) {
2265
- container.innerHTML = "";
2266
- container.appendChild(button);
2267
- if (params.type === "pay" && (data == null ? void 0 : data.isLoggedIn)) {
2268
- button.addEventListener("click", (e) => {
2269
- var _a2;
2270
- e.preventDefault();
2271
- if (params == null ? void 0 : params.callback) {
2272
- (_a2 = params == null ? void 0 : params.callback) == null ? void 0 : _a2.call(params);
2273
- } else if (params.orderInfo) {
2274
- triggerPostMessageToCore(PPFunctionName.makePayment, true, params, __spreadValues({}, params.orderInfo));
2275
- }
2276
- });
2277
- }
2278
- }
2272
+ function verifyMultiFactorAuthResult(params) {
2273
+ const url = new URL(window.location.href);
2274
+ triggerPostMessageToCore(
2275
+ PPFunctionName.verifyMultiFactorAuthResult,
2276
+ false,
2277
+ params,
2278
+ __spreadProps(__spreadValues({}, params), { sessionId: url.searchParams.get("ppSessionId") })
2279
+ );
2279
2280
  }
2280
- const markAsReady = promiseToCallback(
2281
- "markAsReady",
2282
- () => __async(void 0, null, function* () {
2283
- yield core.markAsReady();
2284
- }),
2285
- getCore
2286
- );
2287
- const clientJsBridge = {
2288
- _handleMessageFromNative: (json) => {
2289
- void getCoreIframe().then((iframe) => {
2290
- var _a;
2291
- (_a = iframe == null ? void 0 : iframe.contentWindow) == null ? void 0 : _a.postMessage(
2292
- JSON.parse(
2293
- JSON.stringify({
2294
- name: PPFunctionName.handleMessageFromNative,
2295
- params: {
2296
- json
2297
- }
2298
- })
2299
- ),
2300
- CORE_IFRAME_ORIGIN
2301
- );
2302
- });
2303
- }
2304
- };
2305
- exposeClientJsBridge(clientJsBridge);
2306
2281
  const clientFunctions = {
2307
- // functions that run on client, or need special treatment on client
2308
- init,
2309
2282
  verifyMultiFactorAuthResult,
2310
2283
  share,
2311
2284
  setTitle,
2312
- render,
2313
2285
  renderCoupons,
2314
2286
  scanCode,
2315
2287
  copyToClipboard,
@@ -2321,95 +2293,9 @@ const clientFunctions = {
2321
2293
  getKycPassportInfo,
2322
2294
  logout,
2323
2295
  getPaymentSettings,
2324
- getLoginUrl,
2325
2296
  markAsReady
2326
2297
  };
2327
- const initExemptedFunctions = [
2328
- "init",
2329
- "setTitle",
2330
- "copyToClipboard",
2331
- "getSessionData",
2332
- "setSessionData",
2333
- "getStorageData",
2334
- "setStorageData",
2335
- "removeStorageData",
2336
- "getLoginUrl"
2337
- ];
2338
- const autoInitFunctions = ["renderCoupons"];
2339
- function executePendingFunctionCalls(client2) {
2340
- const pendingFunctionCalls = window._ppcs;
2341
- if (!pendingFunctionCalls) {
2342
- return;
2343
- }
2344
- window._ppcs = void 0;
2345
- for (const [functionName, params, resolve] of pendingFunctionCalls) {
2346
- const resultPromise = client2[functionName](params);
2347
- if (resolve) {
2348
- resolve(resultPromise);
2349
- }
2350
- }
2351
- }
2352
- const clientProperties = {
2353
- version: "2.46.0",
2354
- revision: "bd28c67"
2355
- };
2356
- function isInitClientParams(params) {
2357
- return params.clientId !== void 0;
2358
- }
2359
- function getClient({ sdkType }) {
2360
- clientSdkType = sdkType;
2361
- const isSupportedFunction = sdkType === SdkType.MiniApp ? isSupportedMiniapp : isSupportedSmartpayment;
2362
- const proxy = new Proxy(clientFunctions, {
2363
- get(target, prop) {
2364
- if (prop in clientProperties) {
2365
- return clientProperties[prop];
2366
- }
2367
- const functionName = prop;
2368
- if (!useAllFunctions) {
2369
- if (!isSupportedFunction(functionName)) {
2370
- throw new Error(
2371
- `${functionName} is not supported by ${sdkType} JS SDK`
2372
- );
2373
- }
2374
- }
2375
- function callSdkFunction(params) {
2376
- return __async(this, null, function* () {
2377
- var _a, _b;
2378
- if (!initExemptedFunctions.includes(functionName) && !(yield initDonePromise)) {
2379
- if (autoInitFunctions.includes(functionName) && isInitClientParams(params)) {
2380
- init({
2381
- clientId: params.clientId,
2382
- env: params.env
2383
- });
2384
- yield initDonePromise;
2385
- } else {
2386
- (_a = params.fail) == null ? void 0 : _a.call(params, {
2387
- errorCode: MiniAppErrorType.sdkNotInitialized
2388
- });
2389
- (_b = params.complete) == null ? void 0 : _b.call(params);
2390
- return;
2391
- }
2392
- }
2393
- if (Object.prototype.hasOwnProperty.call(target, functionName)) {
2394
- return target[functionName](params);
2395
- }
2396
- triggerPostMessageToCore(
2397
- prop,
2398
- false,
2399
- params,
2400
- params
2401
- );
2402
- });
2403
- }
2404
- return callbackToPromise(callSdkFunction, functionName);
2405
- }
2406
- });
2407
- const client2 = proxy;
2408
- window._pp = client2;
2409
- executePendingFunctionCalls(client2);
2410
- return client2;
2411
- }
2412
- const client = getClient({ sdkType: SdkType.MiniApp });
2298
+ const client = getClient({ sdkType: SdkType.MiniApp, clientFunctions });
2413
2299
  const miniAppSdk = client;
2414
2300
  export {
2415
2301
  miniAppSdk as default