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.
@@ -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,36 @@ 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
- const apiBaseUrl = searchParams.get("apiBaseUrl") || searchParams.get("apiUrl") || "";
1902
- const serverKey = searchParams.get("serverKey") || "";
1903
- if (sessionId && apiBaseUrl && serverKey) {
1904
- setConfig({
1905
- apiBaseUrl,
1906
- sessionId,
1907
- serverKey
1908
- });
1909
- } else if (sessionId) {
1910
- console.error("Missing required parameters: apiBaseUrl and serverKey must be in URL");
1977
+ if (sessionId) {
1978
+ const storedConfig = getKycConfig(sessionId);
1979
+ if (storedConfig) {
1980
+ setConfig({
1981
+ apiBaseUrl: storedConfig.apiBaseUrl,
1982
+ sessionId,
1983
+ serverKey: storedConfig.serverKey
1984
+ });
1985
+ } else {
1986
+ const apiBaseUrl = searchParams.get("apiBaseUrl") || searchParams.get("apiUrl") || "";
1987
+ const serverKey = searchParams.get("serverKey") || "";
1988
+ if (apiBaseUrl && serverKey) {
1989
+ setConfig({
1990
+ apiBaseUrl,
1991
+ sessionId,
1992
+ serverKey
1993
+ });
1994
+ } else {
1995
+ console.error("Missing required parameters: apiBaseUrl and serverKey not found in localStorage or URL");
1996
+ }
1997
+ }
1998
+ } else {
1999
+ console.error("Missing required parameter: sessionId must be in URL");
1911
2000
  }
1912
2001
  }, [onNavigate]);
1913
2002
  const handleClose = () => {
@@ -1938,7 +2027,7 @@ function MobileRoute({ onClose, onNavigate } = {}) {
1938
2027
  }
1939
2028
  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
2029
  /* @__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, apiBaseUrl, and serverKey parameters." })
2030
+ /* @__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
2031
  ] }) });
1943
2032
  }
1944
2033
  var MobileRoute_default = MobileRoute;
@@ -1946,20 +2035,14 @@ function QRCodePage({ onClose, mobileBaseUrl = "https://kyc-sdk.astraprotocol.co
1946
2035
  const [qrUrl, setQrUrl] = React.useState("");
1947
2036
  const [copied, setCopied] = React.useState(false);
1948
2037
  React.useEffect(() => {
1949
- const searchParams = new URLSearchParams(window.location.search);
1950
- if (sessionId) {
1951
- searchParams.set("sessionId", sessionId);
1952
- }
1953
- if (apiBaseUrl) {
1954
- searchParams.set("apiBaseUrl", apiBaseUrl);
2038
+ if (sessionId && apiBaseUrl && serverKey) {
2039
+ storeKycConfig(sessionId, apiBaseUrl, serverKey);
1955
2040
  }
1956
- if (serverKey) {
1957
- searchParams.set("serverKey", serverKey);
2041
+ if (sessionId) {
2042
+ const mobileRoute = "/mobileroute";
2043
+ const fullUrl = `${mobileBaseUrl}${mobileRoute}?sessionId=${sessionId}`;
2044
+ setQrUrl(fullUrl);
1958
2045
  }
1959
- const mobileRoute = "/mobileroute";
1960
- const queryString = searchParams.toString();
1961
- const fullUrl = `${mobileBaseUrl}${mobileRoute}${queryString ? `?${queryString}` : ""}`;
1962
- setQrUrl(fullUrl);
1963
2046
  }, [mobileBaseUrl, sessionId, apiBaseUrl, serverKey]);
1964
2047
  const handleCopyUrl = async () => {
1965
2048
  if (qrUrl) {