astra-sdk-web 1.1.27 → 1.1.28
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 +106 -23
- package/dist/astra-sdk.cjs.js.map +1 -1
- package/dist/astra-sdk.es.js +106 -23
- package/dist/astra-sdk.es.js.map +1 -1
- package/dist/components.cjs.js +106 -23
- package/dist/components.cjs.js.map +1 -1
- package/dist/components.es.js +106 -23
- package/dist/components.es.js.map +1 -1
- package/package.json +1 -1
- package/src/pages/MobileRoute.tsx +33 -14
- package/src/pages/QRCodePage.tsx +10 -17
- package/src/utils/kycConfigStorage.ts +125 -0
package/dist/astra-sdk.es.js
CHANGED
|
@@ -477,6 +477,81 @@ function isMobileDevice() {
|
|
|
477
477
|
const hasTouchScreen = "ontouchstart" in window || navigator.maxTouchPoints > 0;
|
|
478
478
|
return mobileRegex.test(userAgent) || isSmallScreen && hasTouchScreen;
|
|
479
479
|
}
|
|
480
|
+
|
|
481
|
+
// src/utils/kycConfigStorage.ts
|
|
482
|
+
var STORAGE_PREFIX = "kyc_config_";
|
|
483
|
+
var STORAGE_EXPIRY_MS = 24 * 60 * 60 * 1e3;
|
|
484
|
+
function storeKycConfig(sessionId, apiBaseUrl, serverKey) {
|
|
485
|
+
if (!sessionId || !apiBaseUrl || !serverKey) {
|
|
486
|
+
console.warn("Cannot store KYC config: missing required parameters");
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
try {
|
|
490
|
+
const config = {
|
|
491
|
+
apiBaseUrl,
|
|
492
|
+
serverKey,
|
|
493
|
+
sessionId
|
|
494
|
+
};
|
|
495
|
+
const storageKey = `${STORAGE_PREFIX}${sessionId}`;
|
|
496
|
+
const data = {
|
|
497
|
+
config,
|
|
498
|
+
timestamp: Date.now()
|
|
499
|
+
};
|
|
500
|
+
localStorage.setItem(storageKey, JSON.stringify(data));
|
|
501
|
+
} catch (error) {
|
|
502
|
+
console.error("Failed to store KYC config:", error);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
function getKycConfig(sessionId) {
|
|
506
|
+
if (!sessionId) {
|
|
507
|
+
return null;
|
|
508
|
+
}
|
|
509
|
+
try {
|
|
510
|
+
const storageKey = `${STORAGE_PREFIX}${sessionId}`;
|
|
511
|
+
const stored = localStorage.getItem(storageKey);
|
|
512
|
+
if (!stored) {
|
|
513
|
+
return null;
|
|
514
|
+
}
|
|
515
|
+
const data = JSON.parse(stored);
|
|
516
|
+
if (data.timestamp && Date.now() - data.timestamp > STORAGE_EXPIRY_MS) {
|
|
517
|
+
localStorage.removeItem(storageKey);
|
|
518
|
+
return null;
|
|
519
|
+
}
|
|
520
|
+
if (data.config && data.config.apiBaseUrl && data.config.serverKey) {
|
|
521
|
+
return {
|
|
522
|
+
apiBaseUrl: data.config.apiBaseUrl,
|
|
523
|
+
serverKey: data.config.serverKey
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
return null;
|
|
527
|
+
} catch (error) {
|
|
528
|
+
console.error("Failed to retrieve KYC config:", error);
|
|
529
|
+
return null;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
function clearExpiredConfigs() {
|
|
533
|
+
try {
|
|
534
|
+
const keys = Object.keys(localStorage);
|
|
535
|
+
const now = Date.now();
|
|
536
|
+
keys.forEach((key) => {
|
|
537
|
+
if (key.startsWith(STORAGE_PREFIX)) {
|
|
538
|
+
try {
|
|
539
|
+
const stored = localStorage.getItem(key);
|
|
540
|
+
if (stored) {
|
|
541
|
+
const data = JSON.parse(stored);
|
|
542
|
+
if (data.timestamp && now - data.timestamp > STORAGE_EXPIRY_MS) {
|
|
543
|
+
localStorage.removeItem(key);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
} catch (error) {
|
|
547
|
+
localStorage.removeItem(key);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
});
|
|
551
|
+
} catch (error) {
|
|
552
|
+
console.error("Failed to clear expired configs:", error);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
480
555
|
function useDocumentUpload(callbacks) {
|
|
481
556
|
const [state, setState] = useState({
|
|
482
557
|
docType: "CNIC",
|
|
@@ -1884,22 +1959,36 @@ function MobileRouteContent({ onClose, onComplete }) {
|
|
|
1884
1959
|
function MobileRoute({ onClose, onNavigate } = {}) {
|
|
1885
1960
|
const [config, setConfig] = useState(null);
|
|
1886
1961
|
useEffect(() => {
|
|
1962
|
+
clearExpiredConfigs();
|
|
1887
1963
|
if (!isMobileDevice() && onNavigate) {
|
|
1888
1964
|
onNavigate("qr");
|
|
1889
1965
|
return;
|
|
1890
1966
|
}
|
|
1891
1967
|
const searchParams = new URLSearchParams(window.location.search);
|
|
1892
1968
|
const sessionId = searchParams.get("sessionId");
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1969
|
+
if (sessionId) {
|
|
1970
|
+
const storedConfig = getKycConfig(sessionId);
|
|
1971
|
+
if (storedConfig) {
|
|
1972
|
+
setConfig({
|
|
1973
|
+
apiBaseUrl: storedConfig.apiBaseUrl,
|
|
1974
|
+
sessionId,
|
|
1975
|
+
serverKey: storedConfig.serverKey
|
|
1976
|
+
});
|
|
1977
|
+
} else {
|
|
1978
|
+
const apiBaseUrl = searchParams.get("apiBaseUrl") || searchParams.get("apiUrl") || "";
|
|
1979
|
+
const serverKey = searchParams.get("serverKey") || "";
|
|
1980
|
+
if (apiBaseUrl && serverKey) {
|
|
1981
|
+
setConfig({
|
|
1982
|
+
apiBaseUrl,
|
|
1983
|
+
sessionId,
|
|
1984
|
+
serverKey
|
|
1985
|
+
});
|
|
1986
|
+
} else {
|
|
1987
|
+
console.error("Missing required parameters: apiBaseUrl and serverKey not found in localStorage or URL");
|
|
1988
|
+
}
|
|
1989
|
+
}
|
|
1990
|
+
} else {
|
|
1991
|
+
console.error("Missing required parameter: sessionId must be in URL");
|
|
1903
1992
|
}
|
|
1904
1993
|
}, [onNavigate]);
|
|
1905
1994
|
const handleClose = () => {
|
|
@@ -1930,7 +2019,7 @@ function MobileRoute({ onClose, onNavigate } = {}) {
|
|
|
1930
2019
|
}
|
|
1931
2020
|
return /* @__PURE__ */ jsx("div", { className: "fixed inset-0 flex items-center justify-center bg-black/50 z-[1000]", children: /* @__PURE__ */ jsxs("div", { className: "bg-white p-6 rounded-lg text-center max-w-md mx-4", children: [
|
|
1932
2021
|
/* @__PURE__ */ jsx("p", { className: "text-red-600 mb-2", children: "Missing Configuration" }),
|
|
1933
|
-
/* @__PURE__ */ jsx("p", { className: "text-sm text-gray-600", children: "Please ensure the URL includes sessionId
|
|
2022
|
+
/* @__PURE__ */ 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." })
|
|
1934
2023
|
] }) });
|
|
1935
2024
|
}
|
|
1936
2025
|
var MobileRoute_default = MobileRoute;
|
|
@@ -1938,20 +2027,14 @@ function QRCodePage({ onClose, mobileBaseUrl = "https://kyc-sdk.astraprotocol.co
|
|
|
1938
2027
|
const [qrUrl, setQrUrl] = useState("");
|
|
1939
2028
|
const [copied, setCopied] = useState(false);
|
|
1940
2029
|
useEffect(() => {
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
searchParams.set("sessionId", sessionId);
|
|
1944
|
-
}
|
|
1945
|
-
if (apiBaseUrl) {
|
|
1946
|
-
searchParams.set("apiBaseUrl", apiBaseUrl);
|
|
2030
|
+
if (sessionId && apiBaseUrl && serverKey) {
|
|
2031
|
+
storeKycConfig(sessionId, apiBaseUrl, serverKey);
|
|
1947
2032
|
}
|
|
1948
|
-
if (
|
|
1949
|
-
|
|
2033
|
+
if (sessionId) {
|
|
2034
|
+
const mobileRoute = "/mobileroute";
|
|
2035
|
+
const fullUrl = `${mobileBaseUrl}${mobileRoute}?sessionId=${sessionId}`;
|
|
2036
|
+
setQrUrl(fullUrl);
|
|
1950
2037
|
}
|
|
1951
|
-
const mobileRoute = "/mobileroute";
|
|
1952
|
-
const queryString = searchParams.toString();
|
|
1953
|
-
const fullUrl = `${mobileBaseUrl}${mobileRoute}${queryString ? `?${queryString}` : ""}`;
|
|
1954
|
-
setQrUrl(fullUrl);
|
|
1955
2038
|
}, [mobileBaseUrl, sessionId, apiBaseUrl, serverKey]);
|
|
1956
2039
|
const handleCopyUrl = async () => {
|
|
1957
2040
|
if (qrUrl) {
|