@paypay/mini-app-js-sdk 2.46.0 → 2.49.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/client/clientUtils.d.ts +1 -1
- package/dist/client/communicationWithCore.d.ts +16 -0
- package/dist/client/functions/copyToClipboard.d.ts +2 -0
- package/dist/client/functions/coreWindowBridgeFunctions.d.ts +12 -0
- package/dist/client/functions/getKycPassportInfo.d.ts +3 -0
- package/dist/client/functions/logout.d.ts +6 -0
- package/dist/client/functions/renderCoupons.d.ts +6 -0
- package/dist/client/functions/scanCode.d.ts +2 -0
- package/dist/client/functions/setTitle.d.ts +2 -0
- package/dist/client/functions/share.d.ts +2 -0
- package/dist/client/functions/storageFunctions.d.ts +6 -0
- package/dist/client/functions/verifyMultiFactorAuthResult.d.ts +3 -0
- package/dist/client/index.d.ts +4 -59
- package/dist/client/types.d.ts +37 -2
- package/dist/client/{clientFunctions → windowBridgeFunctions}/storageFunctions.d.ts +10 -0
- package/dist/client/{clientFunctions → windowBridgeFunctions}/urlFunctions.d.ts +1 -0
- package/dist/core/coreFunctions/getLoginUrl.d.ts +1 -1
- package/dist/core/coreUtils.d.ts +1 -1
- package/dist/mini-app-js-sdk.browser.js +1 -1
- package/dist/mini-app-js-sdk.es.js +459 -562
- package/dist/model/bridge/getTopBarHeight.d.ts +1 -1
- package/dist/package/lottie/lottie.d.ts +6 -6
- package/dist/types/init.d.ts +0 -2
- package/dist/types/makePayment.d.ts +2 -1
- package/dist/types.d.ts +1 -1
- package/dist/utils/getAppDetail.d.ts +1 -0
- package/dist/utils/helper.d.ts +5 -2
- package/dist/views/coupon/components/Arrow/index.d.ts +5 -5
- package/dist/views/coupon/components/CouponAction/index.d.ts +4 -4
- package/dist/views/coupon/components/CouponContainer/index.d.ts +3 -3
- package/dist/views/coupon/index.d.ts +4 -4
- package/package.json +9 -9
- package/dist/types/getLoginUrl.d.ts +0 -8
- /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.
|
|
388
|
-
const REVISION = "
|
|
382
|
+
const JS_SDK_VERSION = "2.49.0";
|
|
383
|
+
const REVISION = "a7eaf68";
|
|
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
|
|
1744
|
-
removeParams.forEach((param) =>
|
|
1745
|
-
const newURL = `${
|
|
1746
|
-
history.replaceState(
|
|
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,420 @@ 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
|
-
|
|
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
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
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 (
|
|
1863
|
-
|
|
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 (
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
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
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
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
|
-
|
|
1912
|
-
(_a =
|
|
1913
|
-
|
|
1914
|
-
|
|
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
|
-
});
|
|
1926
|
-
initDonePromise = nextInitDonePromise;
|
|
1927
|
-
}
|
|
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") })
|
|
1935
|
-
);
|
|
1936
|
-
}
|
|
1937
|
-
function getKycPassportInfo(params) {
|
|
1938
|
-
const url2 = window.location.href;
|
|
1939
|
-
triggerPostMessageToCore(PPFunctionName.getKycPassportInfo, false, params, __spreadProps(__spreadValues({}, params), {
|
|
1940
|
-
url: url2
|
|
1941
|
-
}));
|
|
1942
|
-
}
|
|
1943
|
-
function share(params) {
|
|
1944
|
-
if (!(navigator == null ? void 0 : navigator.share)) {
|
|
1945
|
-
triggerPostMessageToCore(PPFunctionName.share, false, params, params);
|
|
1946
|
-
return;
|
|
1947
|
-
}
|
|
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
|
|
1952
|
-
};
|
|
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);
|
|
1957
|
-
}).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);
|
|
1961
1764
|
});
|
|
1962
1765
|
}
|
|
1963
|
-
function
|
|
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
|
|
1974
|
-
});
|
|
1975
|
-
(_b = params.complete) == null ? void 0 : _b.call(params);
|
|
1976
|
-
return console.error("Invalid container Id");
|
|
1977
|
-
}
|
|
1766
|
+
function triggerPostMessageToCore(type, showIframeFlag, params, postMessageParams) {
|
|
1978
1767
|
const messageId = functionStart();
|
|
1979
|
-
const
|
|
1980
|
-
|
|
1981
|
-
if (!checkIFrameOrigin(e.origin) || e.data.name !== PPFunctionName.render || e.data.messageId !== messageId) {
|
|
1768
|
+
const fnMessageHandler = (e) => {
|
|
1769
|
+
if (!checkIFrameOrigin(e.origin)) {
|
|
1982
1770
|
return;
|
|
1983
1771
|
}
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
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));
|
|
1772
|
+
if (e.data.name === type) {
|
|
1773
|
+
if (e.data.messageId === messageId) {
|
|
1774
|
+
receiveMessageFromIframe(e.data, params, fnMessageHandler);
|
|
1990
1775
|
}
|
|
1991
1776
|
}
|
|
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
1777
|
};
|
|
2000
|
-
addEventListener("message",
|
|
1778
|
+
addEventListener("message", fnMessageHandler);
|
|
2001
1779
|
void postMessageToCore({
|
|
2002
|
-
name:
|
|
2003
|
-
params:
|
|
2004
|
-
redirectUrl: params.redirectUrl || window.location.href
|
|
2005
|
-
}),
|
|
1780
|
+
name: type,
|
|
1781
|
+
params: postMessageParams,
|
|
2006
1782
|
messageId
|
|
2007
1783
|
});
|
|
2008
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}`
|
|
1791
|
+
);
|
|
1792
|
+
return refreshTokenWithClientId || api.get(PpLocalStorageKey.refreshToken) || "";
|
|
1793
|
+
}
|
|
1794
|
+
function getCodeVerifier(clientId) {
|
|
1795
|
+
return api.get(`${PpLocalStorageKey.codeVerifier}.${clientId}`) || api.get(PpLocalStorageKey.codeVerifier) || "";
|
|
1796
|
+
}
|
|
1797
|
+
function exposeClientJsBridge(jsBridge) {
|
|
1798
|
+
if (window.hasOwnProperty(jsBridgeNamespace) && window[jsBridgeNamespace] === jsBridge) {
|
|
1799
|
+
return false;
|
|
1800
|
+
}
|
|
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;
|
|
1858
|
+
};
|
|
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
|
+
let _error;
|
|
1869
|
+
let _result;
|
|
1870
|
+
target(__spreadProps(__spreadValues({}, params), {
|
|
1871
|
+
success: (result) => {
|
|
1872
|
+
var _a;
|
|
1873
|
+
_result = result;
|
|
1874
|
+
(_a = params.success) == null ? void 0 : _a.call(params, result);
|
|
1875
|
+
},
|
|
1876
|
+
fail: (error) => {
|
|
1877
|
+
var _a;
|
|
1878
|
+
if (functionName === "init" && INIT_STATUS_CODE_REMAP[error.errorCode]) {
|
|
1879
|
+
_result = {
|
|
1880
|
+
statusCode: INIT_STATUS_CODE_REMAP[error.errorCode]
|
|
1881
|
+
};
|
|
1882
|
+
} else {
|
|
1883
|
+
_error = error;
|
|
1884
|
+
}
|
|
1885
|
+
(_a = params.fail) == null ? void 0 : _a.call(params, error);
|
|
1886
|
+
},
|
|
1887
|
+
complete: () => {
|
|
1888
|
+
var _a;
|
|
1889
|
+
if (_error) {
|
|
1890
|
+
reject(_error);
|
|
1891
|
+
} else {
|
|
1892
|
+
resolve(_result);
|
|
1893
|
+
}
|
|
1894
|
+
(_a = params.complete) == null ? void 0 : _a.call(params);
|
|
1895
|
+
}
|
|
1896
|
+
}));
|
|
1897
|
+
});
|
|
1898
|
+
};
|
|
1899
|
+
}
|
|
1900
|
+
let clientSdkType;
|
|
1901
|
+
let initDonePromise;
|
|
1902
|
+
void getCoreIframe();
|
|
1903
|
+
function clearInternalInitSyncState() {
|
|
1904
|
+
initDonePromise = Promise.resolve(false);
|
|
1905
|
+
}
|
|
1906
|
+
clearInternalInitSyncState();
|
|
1907
|
+
const commonMessageHandler = (e) => {
|
|
1908
|
+
var _a;
|
|
1909
|
+
if ((_a = e.data) == null ? void 0 : _a.forWindowBridge) {
|
|
1910
|
+
return;
|
|
1911
|
+
}
|
|
1912
|
+
if (!checkIFrameOrigin(e.origin)) {
|
|
1913
|
+
return;
|
|
1914
|
+
}
|
|
1915
|
+
if (e.data.name === PPUtilFunctionName.reload) {
|
|
1916
|
+
window.location.reload();
|
|
1917
|
+
}
|
|
1918
|
+
if (e.data.name === PPUtilFunctionName.makeVisible) {
|
|
1919
|
+
showCoreIframe(true);
|
|
1920
|
+
return;
|
|
1921
|
+
}
|
|
1922
|
+
if (e.data.name === PPUtilFunctionName.link) {
|
|
1923
|
+
const linkOption = e.data.data;
|
|
1924
|
+
if (linkOption.target === "_blank") {
|
|
1925
|
+
window.open(linkOption.url, "_blank");
|
|
1926
|
+
} else {
|
|
1927
|
+
window.location.href = linkOption.url;
|
|
1928
|
+
}
|
|
1929
|
+
}
|
|
1930
|
+
if (e.data.name === PPUtilFunctionName.consoleDebugInfo) {
|
|
1931
|
+
const { params } = e.data.data;
|
|
1932
|
+
consoleDebugInfo(params);
|
|
1933
|
+
}
|
|
1934
|
+
};
|
|
1935
|
+
addEventListener("message", commonMessageHandler);
|
|
1936
|
+
addEventListener("popstate", () => {
|
|
1937
|
+
getCoreIframe().then((iframe) => {
|
|
1938
|
+
var _a;
|
|
1939
|
+
const data = {
|
|
1940
|
+
name: PPUtilFunctionName.clientPopState
|
|
1941
|
+
};
|
|
1942
|
+
(_a = iframe == null ? void 0 : iframe.contentWindow) == null ? void 0 : _a.postMessage(data, CORE_IFRAME_ORIGIN);
|
|
1943
|
+
}).catch((error) => console.warn(error));
|
|
1944
|
+
});
|
|
1945
|
+
function init(params) {
|
|
1946
|
+
const refreshToken = getRefreshToken(params.clientId);
|
|
1947
|
+
const codeVerifier = getCodeVerifier(params.clientId);
|
|
1948
|
+
const clientVersion = "2.49.0";
|
|
1949
|
+
const initParams = {
|
|
1950
|
+
env: params.env,
|
|
1951
|
+
mode: params.mode,
|
|
1952
|
+
debugMode: params.debugMode,
|
|
1953
|
+
clientId: params.clientId,
|
|
1954
|
+
refreshToken,
|
|
1955
|
+
clientVersion,
|
|
1956
|
+
codeVerifier,
|
|
1957
|
+
clientSdkType,
|
|
1958
|
+
clientUrl: window.location.href
|
|
1959
|
+
};
|
|
1960
|
+
let initDonePromiseResolve;
|
|
1961
|
+
const nextInitDonePromise = new Promise(
|
|
1962
|
+
(resolve) => initDonePromiseResolve = resolve
|
|
1963
|
+
);
|
|
1964
|
+
const complete = () => {
|
|
1965
|
+
var _a;
|
|
1966
|
+
initDonePromiseResolve(true);
|
|
1967
|
+
(_a = params.complete) == null ? void 0 : _a.call(params);
|
|
1968
|
+
};
|
|
1969
|
+
initDonePromise.then(() => getCoreIframe()).then(() => {
|
|
1970
|
+
triggerPostMessageToCore(
|
|
1971
|
+
PPFunctionName.init,
|
|
1972
|
+
false,
|
|
1973
|
+
__spreadProps(__spreadValues({}, params), { complete }),
|
|
1974
|
+
initParams
|
|
1975
|
+
);
|
|
1976
|
+
}).catch(() => {
|
|
1977
|
+
var _a;
|
|
1978
|
+
(_a = params.fail) == null ? void 0 : _a.call(params, { errorCode: MiniAppErrorType.sdkNotInitialized });
|
|
1979
|
+
complete();
|
|
1980
|
+
});
|
|
1981
|
+
initDonePromise = nextInitDonePromise;
|
|
1982
|
+
}
|
|
1983
|
+
const clientJsBridge = {
|
|
1984
|
+
_handleMessageFromNative: (json) => {
|
|
1985
|
+
void getCoreIframe().then((iframe) => {
|
|
1986
|
+
var _a;
|
|
1987
|
+
(_a = iframe == null ? void 0 : iframe.contentWindow) == null ? void 0 : _a.postMessage(
|
|
1988
|
+
JSON.parse(
|
|
1989
|
+
JSON.stringify({
|
|
1990
|
+
name: PPFunctionName.handleMessageFromNative,
|
|
1991
|
+
params: {
|
|
1992
|
+
json
|
|
1993
|
+
}
|
|
1994
|
+
})
|
|
1995
|
+
),
|
|
1996
|
+
CORE_IFRAME_ORIGIN
|
|
1997
|
+
);
|
|
1998
|
+
});
|
|
1999
|
+
}
|
|
2000
|
+
};
|
|
2001
|
+
exposeClientJsBridge(clientJsBridge);
|
|
2002
|
+
const initExemptedFunctions = [
|
|
2003
|
+
"init",
|
|
2004
|
+
"setTitle",
|
|
2005
|
+
"copyToClipboard",
|
|
2006
|
+
"getSessionData",
|
|
2007
|
+
"setSessionData",
|
|
2008
|
+
"getStorageData",
|
|
2009
|
+
"setStorageData",
|
|
2010
|
+
"removeStorageData",
|
|
2011
|
+
"getLoginUrl"
|
|
2012
|
+
];
|
|
2013
|
+
const autoInitFunctions = ["renderCoupons"];
|
|
2014
|
+
function executePendingFunctionCalls(client2) {
|
|
2015
|
+
const pendingFunctionCalls = window._ppcs;
|
|
2016
|
+
if (!pendingFunctionCalls) {
|
|
2017
|
+
return;
|
|
2018
|
+
}
|
|
2019
|
+
window._ppcs = void 0;
|
|
2020
|
+
for (const [functionName, params, resolve] of pendingFunctionCalls) {
|
|
2021
|
+
const resultPromise = client2[functionName](params);
|
|
2022
|
+
if (resolve) {
|
|
2023
|
+
resolve(resultPromise);
|
|
2024
|
+
}
|
|
2025
|
+
}
|
|
2026
|
+
}
|
|
2027
|
+
const clientProperties = {
|
|
2028
|
+
version: "2.49.0",
|
|
2029
|
+
revision: "a7eaf68"
|
|
2030
|
+
};
|
|
2031
|
+
function isInitClientParams(params) {
|
|
2032
|
+
return params.clientId !== void 0;
|
|
2033
|
+
}
|
|
2034
|
+
function getClient({
|
|
2035
|
+
sdkType,
|
|
2036
|
+
clientFunctions: clientFunctions2
|
|
2037
|
+
}) {
|
|
2038
|
+
clientSdkType = sdkType;
|
|
2039
|
+
const isSupportedFunction = sdkType === SdkType.MiniApp ? isSupportedMiniapp : isSupportedSmartpayment;
|
|
2040
|
+
const client2 = new Proxy(
|
|
2041
|
+
__spreadProps(__spreadValues({}, clientFunctions2), { init }),
|
|
2042
|
+
{
|
|
2043
|
+
get(target, prop) {
|
|
2044
|
+
if (prop in clientProperties) {
|
|
2045
|
+
return clientProperties[prop];
|
|
2046
|
+
}
|
|
2047
|
+
const functionName = prop;
|
|
2048
|
+
if (!isSupportedFunction(functionName)) {
|
|
2049
|
+
throw new Error(
|
|
2050
|
+
`${functionName} is not supported by ${sdkType} JS SDK`
|
|
2051
|
+
);
|
|
2052
|
+
}
|
|
2053
|
+
function callSdkFunction(params) {
|
|
2054
|
+
return __async(this, null, function* () {
|
|
2055
|
+
var _a, _b;
|
|
2056
|
+
if (!initExemptedFunctions.includes(functionName) && !(yield initDonePromise)) {
|
|
2057
|
+
if (autoInitFunctions.includes(functionName) && isInitClientParams(params)) {
|
|
2058
|
+
init({
|
|
2059
|
+
clientId: params.clientId,
|
|
2060
|
+
env: params.env
|
|
2061
|
+
});
|
|
2062
|
+
yield initDonePromise;
|
|
2063
|
+
} else {
|
|
2064
|
+
(_a = params.fail) == null ? void 0 : _a.call(params, {
|
|
2065
|
+
errorCode: MiniAppErrorType.sdkNotInitialized
|
|
2066
|
+
});
|
|
2067
|
+
(_b = params.complete) == null ? void 0 : _b.call(params);
|
|
2068
|
+
return;
|
|
2069
|
+
}
|
|
2070
|
+
}
|
|
2071
|
+
const fn = target[functionName];
|
|
2072
|
+
if (fn && isFunction(fn)) {
|
|
2073
|
+
return fn(params);
|
|
2074
|
+
}
|
|
2075
|
+
triggerPostMessageToCore(
|
|
2076
|
+
prop,
|
|
2077
|
+
false,
|
|
2078
|
+
params,
|
|
2079
|
+
params
|
|
2080
|
+
);
|
|
2081
|
+
});
|
|
2082
|
+
}
|
|
2083
|
+
return callbackToPromise(callSdkFunction, functionName);
|
|
2084
|
+
}
|
|
2085
|
+
}
|
|
2086
|
+
);
|
|
2087
|
+
window._pp = client2;
|
|
2088
|
+
executePendingFunctionCalls(client2);
|
|
2089
|
+
return client2;
|
|
2090
|
+
}
|
|
2091
|
+
function copyToClipboard(params) {
|
|
2092
|
+
var _a, _b, _c;
|
|
2093
|
+
const textarea = document.createElement("textarea");
|
|
2094
|
+
textarea.setAttribute("readonly", "true");
|
|
2095
|
+
textarea.setAttribute("contenteditable", "true");
|
|
2096
|
+
textarea.value = params.value;
|
|
2097
|
+
document.body.appendChild(textarea);
|
|
2098
|
+
textarea.select();
|
|
2099
|
+
textarea.setSelectionRange(0, textarea.value.length);
|
|
2100
|
+
const result = document.execCommand("copy");
|
|
2101
|
+
document.body.removeChild(textarea);
|
|
2102
|
+
if (result) {
|
|
2103
|
+
(_a = params == null ? void 0 : params.success) == null ? void 0 : _a.call(params);
|
|
2104
|
+
} else {
|
|
2105
|
+
(_b = params == null ? void 0 : params.fail) == null ? void 0 : _b.call(params, { errorCode: MiniAppErrorType.other });
|
|
2106
|
+
}
|
|
2107
|
+
(_c = params.complete) == null ? void 0 : _c.call(params);
|
|
2108
|
+
}
|
|
2109
|
+
promiseToCallback(
|
|
2110
|
+
"getLoginUrl",
|
|
2111
|
+
coreFunctions.getLoginUrl
|
|
2112
|
+
);
|
|
2113
|
+
const getPaymentSettings = promiseToCallback(
|
|
2114
|
+
"getPaymentSettings",
|
|
2115
|
+
coreFunctions.getPaymentSettings
|
|
2116
|
+
);
|
|
2117
|
+
const markAsReady = promiseToCallback(
|
|
2118
|
+
"markAsReady",
|
|
2119
|
+
coreFunctions.markAsReady
|
|
2120
|
+
);
|
|
2121
|
+
function getKycPassportInfo(params) {
|
|
2122
|
+
const url = window.location.href;
|
|
2123
|
+
triggerPostMessageToCore(PPFunctionName.getKycPassportInfo, false, params, __spreadProps(__spreadValues({}, params), {
|
|
2124
|
+
url
|
|
2125
|
+
}));
|
|
2126
|
+
}
|
|
2127
|
+
var MiniAppStatusType = /* @__PURE__ */ ((MiniAppStatusType2) => {
|
|
2128
|
+
MiniAppStatusType2["validToken"] = "TOKEN_VALID";
|
|
2129
|
+
MiniAppStatusType2["initialized"] = "INITIALIZED";
|
|
2130
|
+
MiniAppStatusType2["emailRegistered"] = "EMAIL_REGISTERED";
|
|
2131
|
+
MiniAppStatusType2["emailNotVerified"] = "EMAIL_NOT_VERIFIED";
|
|
2132
|
+
MiniAppStatusType2["success"] = "SUCCESS";
|
|
2133
|
+
MiniAppStatusType2["loggedOut"] = "LOGGED_OUT";
|
|
2134
|
+
MiniAppStatusType2["connected"] = "CONNECTED";
|
|
2135
|
+
return MiniAppStatusType2;
|
|
2136
|
+
})(MiniAppStatusType || {});
|
|
2137
|
+
const logout = promiseToCallback("logout", () => __async(void 0, null, function* () {
|
|
2138
|
+
try {
|
|
2139
|
+
yield coreFunctions.logout();
|
|
2140
|
+
return { statusCode: MiniAppStatusType.loggedOut };
|
|
2141
|
+
} catch (error) {
|
|
2142
|
+
throw new PPError(
|
|
2143
|
+
`An error occurred while trying to logout the user, error=${error}`,
|
|
2144
|
+
MiniAppErrorType.unknown
|
|
2145
|
+
);
|
|
2146
|
+
}
|
|
2147
|
+
}));
|
|
2009
2148
|
const renderCoupons = promiseToCallback(
|
|
2010
2149
|
"renderCoupons",
|
|
2011
2150
|
(params) => __async(void 0, null, function* () {
|
|
@@ -2024,7 +2163,7 @@ const renderCoupons = promiseToCallback(
|
|
|
2024
2163
|
MiniAppErrorType.badRequestInsufficientParameter
|
|
2025
2164
|
);
|
|
2026
2165
|
}
|
|
2027
|
-
const coupons = yield
|
|
2166
|
+
const coupons = yield coreFunctions.fetchCoupons({
|
|
2028
2167
|
merchantId,
|
|
2029
2168
|
couponId,
|
|
2030
2169
|
postLoginRedirectUrl,
|
|
@@ -2063,12 +2202,11 @@ const renderCoupons = promiseToCallback(
|
|
|
2063
2202
|
});
|
|
2064
2203
|
} catch (error) {
|
|
2065
2204
|
throw new PPError(
|
|
2066
|
-
`An error
|
|
2205
|
+
`An error occurred while displaying coupons, merchantId=${merchantId}, couponId=${couponId}, error=${error}`,
|
|
2067
2206
|
MiniAppErrorType.unknown
|
|
2068
2207
|
);
|
|
2069
2208
|
}
|
|
2070
2209
|
}),
|
|
2071
|
-
getCore,
|
|
2072
2210
|
(params) => ({
|
|
2073
2211
|
event_label2: params.couponId,
|
|
2074
2212
|
merchant_id: params.merchant
|
|
@@ -2086,6 +2224,32 @@ function scanCode(params) {
|
|
|
2086
2224
|
scanCodeParams
|
|
2087
2225
|
);
|
|
2088
2226
|
}
|
|
2227
|
+
function setTitle(params) {
|
|
2228
|
+
var _a, _b, _c;
|
|
2229
|
+
document.title = (_a = params == null ? void 0 : params.title) != null ? _a : "";
|
|
2230
|
+
(_b = params == null ? void 0 : params.success) == null ? void 0 : _b.call(params);
|
|
2231
|
+
(_c = params == null ? void 0 : params.complete) == null ? void 0 : _c.call(params);
|
|
2232
|
+
}
|
|
2233
|
+
function share(params) {
|
|
2234
|
+
if (!(navigator == null ? void 0 : navigator.share)) {
|
|
2235
|
+
triggerPostMessageToCore(PPFunctionName.share, false, params, params);
|
|
2236
|
+
return;
|
|
2237
|
+
}
|
|
2238
|
+
const data = {
|
|
2239
|
+
//url: params.imageUrl,
|
|
2240
|
+
//TODO: -> we need to download the imageUrl and try to attach it to `files`
|
|
2241
|
+
text: params == null ? void 0 : params.text
|
|
2242
|
+
};
|
|
2243
|
+
navigator.share(data).then(() => {
|
|
2244
|
+
var _a, _b;
|
|
2245
|
+
(_a = params == null ? void 0 : params.success) == null ? void 0 : _a.call(params);
|
|
2246
|
+
(_b = params == null ? void 0 : params.complete) == null ? void 0 : _b.call(params);
|
|
2247
|
+
}).catch(() => {
|
|
2248
|
+
var _a, _b;
|
|
2249
|
+
(_a = params == null ? void 0 : params.fail) == null ? void 0 : _a.call(params, { errorCode: MiniAppErrorType.unknown });
|
|
2250
|
+
(_b = params == null ? void 0 : params.complete) == null ? void 0 : _b.call(params);
|
|
2251
|
+
});
|
|
2252
|
+
}
|
|
2089
2253
|
function getSessionData(params) {
|
|
2090
2254
|
var _a, _b;
|
|
2091
2255
|
const value = sessionStorage.getItem(params == null ? void 0 : params.key);
|
|
@@ -2116,200 +2280,19 @@ function removeStorageData(params) {
|
|
|
2116
2280
|
(_a = params == null ? void 0 : params.success) == null ? void 0 : _a.call(params);
|
|
2117
2281
|
(_b = params == null ? void 0 : params.complete) == null ? void 0 : _b.call(params);
|
|
2118
2282
|
}
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
(
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
}
|
|
2126
|
-
|
|
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
|
-
}
|
|
2283
|
+
function verifyMultiFactorAuthResult(params) {
|
|
2284
|
+
const url = new URL(window.location.href);
|
|
2285
|
+
triggerPostMessageToCore(
|
|
2286
|
+
PPFunctionName.verifyMultiFactorAuthResult,
|
|
2287
|
+
false,
|
|
2288
|
+
params,
|
|
2289
|
+
__spreadProps(__spreadValues({}, params), { sessionId: url.searchParams.get("ppSessionId") })
|
|
2290
|
+
);
|
|
2279
2291
|
}
|
|
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
2292
|
const clientFunctions = {
|
|
2307
|
-
// functions that run on client, or need special treatment on client
|
|
2308
|
-
init,
|
|
2309
2293
|
verifyMultiFactorAuthResult,
|
|
2310
2294
|
share,
|
|
2311
2295
|
setTitle,
|
|
2312
|
-
render,
|
|
2313
2296
|
renderCoupons,
|
|
2314
2297
|
scanCode,
|
|
2315
2298
|
copyToClipboard,
|
|
@@ -2321,95 +2304,9 @@ const clientFunctions = {
|
|
|
2321
2304
|
getKycPassportInfo,
|
|
2322
2305
|
logout,
|
|
2323
2306
|
getPaymentSettings,
|
|
2324
|
-
getLoginUrl,
|
|
2325
2307
|
markAsReady
|
|
2326
2308
|
};
|
|
2327
|
-
const
|
|
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 });
|
|
2309
|
+
const client = getClient({ sdkType: SdkType.MiniApp, clientFunctions });
|
|
2413
2310
|
const miniAppSdk = client;
|
|
2414
2311
|
export {
|
|
2415
2312
|
miniAppSdk as default
|