astra-sdk-web 1.1.27 → 1.1.29
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/astra-sdk.cjs.js +126 -23
- package/dist/astra-sdk.cjs.js.map +1 -1
- package/dist/astra-sdk.es.js +126 -23
- package/dist/astra-sdk.es.js.map +1 -1
- package/dist/components.cjs.js +126 -23
- package/dist/components.cjs.js.map +1 -1
- package/dist/components.es.js +126 -23
- package/dist/components.es.js.map +1 -1
- package/package.json +1 -1
- package/src/pages/MobileRoute.tsx +51 -15
- package/src/pages/QRCodePage.tsx +18 -17
- package/src/utils/kycConfigStorage.ts +125 -0
package/dist/astra-sdk.cjs.js
CHANGED
|
@@ -485,6 +485,81 @@ function isMobileDevice() {
|
|
|
485
485
|
const hasTouchScreen = "ontouchstart" in window || navigator.maxTouchPoints > 0;
|
|
486
486
|
return mobileRegex.test(userAgent) || isSmallScreen && hasTouchScreen;
|
|
487
487
|
}
|
|
488
|
+
|
|
489
|
+
// src/utils/kycConfigStorage.ts
|
|
490
|
+
var STORAGE_PREFIX = "kyc_config_";
|
|
491
|
+
var STORAGE_EXPIRY_MS = 24 * 60 * 60 * 1e3;
|
|
492
|
+
function storeKycConfig(sessionId, apiBaseUrl, serverKey) {
|
|
493
|
+
if (!sessionId || !apiBaseUrl || !serverKey) {
|
|
494
|
+
console.warn("Cannot store KYC config: missing required parameters");
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
try {
|
|
498
|
+
const config = {
|
|
499
|
+
apiBaseUrl,
|
|
500
|
+
serverKey,
|
|
501
|
+
sessionId
|
|
502
|
+
};
|
|
503
|
+
const storageKey = `${STORAGE_PREFIX}${sessionId}`;
|
|
504
|
+
const data = {
|
|
505
|
+
config,
|
|
506
|
+
timestamp: Date.now()
|
|
507
|
+
};
|
|
508
|
+
localStorage.setItem(storageKey, JSON.stringify(data));
|
|
509
|
+
} catch (error) {
|
|
510
|
+
console.error("Failed to store KYC config:", error);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
function getKycConfig(sessionId) {
|
|
514
|
+
if (!sessionId) {
|
|
515
|
+
return null;
|
|
516
|
+
}
|
|
517
|
+
try {
|
|
518
|
+
const storageKey = `${STORAGE_PREFIX}${sessionId}`;
|
|
519
|
+
const stored = localStorage.getItem(storageKey);
|
|
520
|
+
if (!stored) {
|
|
521
|
+
return null;
|
|
522
|
+
}
|
|
523
|
+
const data = JSON.parse(stored);
|
|
524
|
+
if (data.timestamp && Date.now() - data.timestamp > STORAGE_EXPIRY_MS) {
|
|
525
|
+
localStorage.removeItem(storageKey);
|
|
526
|
+
return null;
|
|
527
|
+
}
|
|
528
|
+
if (data.config && data.config.apiBaseUrl && data.config.serverKey) {
|
|
529
|
+
return {
|
|
530
|
+
apiBaseUrl: data.config.apiBaseUrl,
|
|
531
|
+
serverKey: data.config.serverKey
|
|
532
|
+
};
|
|
533
|
+
}
|
|
534
|
+
return null;
|
|
535
|
+
} catch (error) {
|
|
536
|
+
console.error("Failed to retrieve KYC config:", error);
|
|
537
|
+
return null;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
function clearExpiredConfigs() {
|
|
541
|
+
try {
|
|
542
|
+
const keys = Object.keys(localStorage);
|
|
543
|
+
const now = Date.now();
|
|
544
|
+
keys.forEach((key) => {
|
|
545
|
+
if (key.startsWith(STORAGE_PREFIX)) {
|
|
546
|
+
try {
|
|
547
|
+
const stored = localStorage.getItem(key);
|
|
548
|
+
if (stored) {
|
|
549
|
+
const data = JSON.parse(stored);
|
|
550
|
+
if (data.timestamp && now - data.timestamp > STORAGE_EXPIRY_MS) {
|
|
551
|
+
localStorage.removeItem(key);
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
} catch (error) {
|
|
555
|
+
localStorage.removeItem(key);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
});
|
|
559
|
+
} catch (error) {
|
|
560
|
+
console.error("Failed to clear expired configs:", error);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
488
563
|
function useDocumentUpload(callbacks) {
|
|
489
564
|
const [state, setState] = React.useState({
|
|
490
565
|
docType: "CNIC",
|
|
@@ -1892,22 +1967,50 @@ function MobileRouteContent({ onClose, onComplete }) {
|
|
|
1892
1967
|
function MobileRoute({ onClose, onNavigate } = {}) {
|
|
1893
1968
|
const [config, setConfig] = React.useState(null);
|
|
1894
1969
|
React.useEffect(() => {
|
|
1970
|
+
clearExpiredConfigs();
|
|
1895
1971
|
if (!isMobileDevice() && onNavigate) {
|
|
1896
1972
|
onNavigate("qr");
|
|
1897
1973
|
return;
|
|
1898
1974
|
}
|
|
1899
1975
|
const searchParams = new URLSearchParams(window.location.search);
|
|
1900
1976
|
const sessionId = searchParams.get("sessionId");
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1977
|
+
if (sessionId) {
|
|
1978
|
+
let apiBaseUrl = "";
|
|
1979
|
+
let serverKey = "";
|
|
1980
|
+
const encodedConfig = searchParams.get("config");
|
|
1981
|
+
if (encodedConfig) {
|
|
1982
|
+
try {
|
|
1983
|
+
const decodedConfig = JSON.parse(atob(encodedConfig));
|
|
1984
|
+
if (decodedConfig.apiBaseUrl && decodedConfig.serverKey) {
|
|
1985
|
+
apiBaseUrl = decodedConfig.apiBaseUrl;
|
|
1986
|
+
serverKey = decodedConfig.serverKey;
|
|
1987
|
+
}
|
|
1988
|
+
} catch (error) {
|
|
1989
|
+
console.error("Failed to decode config from URL:", error);
|
|
1990
|
+
}
|
|
1991
|
+
}
|
|
1992
|
+
if (!apiBaseUrl || !serverKey) {
|
|
1993
|
+
const storedConfig = getKycConfig(sessionId);
|
|
1994
|
+
if (storedConfig) {
|
|
1995
|
+
apiBaseUrl = storedConfig.apiBaseUrl;
|
|
1996
|
+
serverKey = storedConfig.serverKey;
|
|
1997
|
+
}
|
|
1998
|
+
}
|
|
1999
|
+
if (!apiBaseUrl || !serverKey) {
|
|
2000
|
+
apiBaseUrl = searchParams.get("apiBaseUrl") || searchParams.get("apiUrl") || "";
|
|
2001
|
+
serverKey = searchParams.get("serverKey") || "";
|
|
2002
|
+
}
|
|
2003
|
+
if (apiBaseUrl && serverKey) {
|
|
2004
|
+
setConfig({
|
|
2005
|
+
apiBaseUrl,
|
|
2006
|
+
sessionId,
|
|
2007
|
+
serverKey
|
|
2008
|
+
});
|
|
2009
|
+
} else {
|
|
2010
|
+
console.error("Missing required parameters: apiBaseUrl and serverKey not found in URL config, localStorage, or URL params");
|
|
2011
|
+
}
|
|
2012
|
+
} else {
|
|
2013
|
+
console.error("Missing required parameter: sessionId must be in URL");
|
|
1911
2014
|
}
|
|
1912
2015
|
}, [onNavigate]);
|
|
1913
2016
|
const handleClose = () => {
|
|
@@ -1938,7 +2041,7 @@ function MobileRoute({ onClose, onNavigate } = {}) {
|
|
|
1938
2041
|
}
|
|
1939
2042
|
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "fixed inset-0 flex items-center justify-center bg-black/50 z-[1000]", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-white p-6 rounded-lg text-center max-w-md mx-4", children: [
|
|
1940
2043
|
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-red-600 mb-2", children: "Missing Configuration" }),
|
|
1941
|
-
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-gray-600", children: "Please ensure the URL includes sessionId
|
|
2044
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-gray-600", children: "Please ensure the URL includes sessionId parameter. The configuration should be stored automatically when scanning the QR code." })
|
|
1942
2045
|
] }) });
|
|
1943
2046
|
}
|
|
1944
2047
|
var MobileRoute_default = MobileRoute;
|
|
@@ -1946,20 +2049,20 @@ function QRCodePage({ onClose, mobileBaseUrl = "https://kyc-sdk.astraprotocol.co
|
|
|
1946
2049
|
const [qrUrl, setQrUrl] = React.useState("");
|
|
1947
2050
|
const [copied, setCopied] = React.useState(false);
|
|
1948
2051
|
React.useEffect(() => {
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
searchParams.set("sessionId", sessionId);
|
|
1952
|
-
}
|
|
1953
|
-
if (apiBaseUrl) {
|
|
1954
|
-
searchParams.set("apiBaseUrl", apiBaseUrl);
|
|
2052
|
+
if (sessionId && apiBaseUrl && serverKey) {
|
|
2053
|
+
storeKycConfig(sessionId, apiBaseUrl, serverKey);
|
|
1955
2054
|
}
|
|
1956
|
-
if (serverKey) {
|
|
1957
|
-
|
|
2055
|
+
if (sessionId && apiBaseUrl && serverKey) {
|
|
2056
|
+
const mobileRoute = "/mobileroute";
|
|
2057
|
+
const config = JSON.stringify({ apiBaseUrl, serverKey });
|
|
2058
|
+
const encodedConfig = btoa(config);
|
|
2059
|
+
const fullUrl = `${mobileBaseUrl}${mobileRoute}?sessionId=${sessionId}&config=${encodedConfig}`;
|
|
2060
|
+
setQrUrl(fullUrl);
|
|
2061
|
+
} else if (sessionId) {
|
|
2062
|
+
const mobileRoute = "/mobileroute";
|
|
2063
|
+
const fullUrl = `${mobileBaseUrl}${mobileRoute}?sessionId=${sessionId}`;
|
|
2064
|
+
setQrUrl(fullUrl);
|
|
1958
2065
|
}
|
|
1959
|
-
const mobileRoute = "/mobileroute";
|
|
1960
|
-
const queryString = searchParams.toString();
|
|
1961
|
-
const fullUrl = `${mobileBaseUrl}${mobileRoute}${queryString ? `?${queryString}` : ""}`;
|
|
1962
|
-
setQrUrl(fullUrl);
|
|
1963
2066
|
}, [mobileBaseUrl, sessionId, apiBaseUrl, serverKey]);
|
|
1964
2067
|
const handleCopyUrl = async () => {
|
|
1965
2068
|
if (qrUrl) {
|