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.
@@ -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,50 @@ 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
- const apiBaseUrl = searchParams.get("apiBaseUrl") || searchParams.get("apiUrl") || "";
1894
- const serverKey = searchParams.get("serverKey") || "";
1895
- if (sessionId && apiBaseUrl && serverKey) {
1896
- setConfig({
1897
- apiBaseUrl,
1898
- sessionId,
1899
- serverKey
1900
- });
1901
- } else if (sessionId) {
1902
- console.error("Missing required parameters: apiBaseUrl and serverKey must be in URL");
1969
+ if (sessionId) {
1970
+ let apiBaseUrl = "";
1971
+ let serverKey = "";
1972
+ const encodedConfig = searchParams.get("config");
1973
+ if (encodedConfig) {
1974
+ try {
1975
+ const decodedConfig = JSON.parse(atob(encodedConfig));
1976
+ if (decodedConfig.apiBaseUrl && decodedConfig.serverKey) {
1977
+ apiBaseUrl = decodedConfig.apiBaseUrl;
1978
+ serverKey = decodedConfig.serverKey;
1979
+ }
1980
+ } catch (error) {
1981
+ console.error("Failed to decode config from URL:", error);
1982
+ }
1983
+ }
1984
+ if (!apiBaseUrl || !serverKey) {
1985
+ const storedConfig = getKycConfig(sessionId);
1986
+ if (storedConfig) {
1987
+ apiBaseUrl = storedConfig.apiBaseUrl;
1988
+ serverKey = storedConfig.serverKey;
1989
+ }
1990
+ }
1991
+ if (!apiBaseUrl || !serverKey) {
1992
+ apiBaseUrl = searchParams.get("apiBaseUrl") || searchParams.get("apiUrl") || "";
1993
+ serverKey = searchParams.get("serverKey") || "";
1994
+ }
1995
+ if (apiBaseUrl && serverKey) {
1996
+ setConfig({
1997
+ apiBaseUrl,
1998
+ sessionId,
1999
+ serverKey
2000
+ });
2001
+ } else {
2002
+ console.error("Missing required parameters: apiBaseUrl and serverKey not found in URL config, localStorage, or URL params");
2003
+ }
2004
+ } else {
2005
+ console.error("Missing required parameter: sessionId must be in URL");
1903
2006
  }
1904
2007
  }, [onNavigate]);
1905
2008
  const handleClose = () => {
@@ -1930,7 +2033,7 @@ function MobileRoute({ onClose, onNavigate } = {}) {
1930
2033
  }
1931
2034
  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
2035
  /* @__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, apiBaseUrl, and serverKey parameters." })
2036
+ /* @__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
2037
  ] }) });
1935
2038
  }
1936
2039
  var MobileRoute_default = MobileRoute;
@@ -1938,20 +2041,20 @@ function QRCodePage({ onClose, mobileBaseUrl = "https://kyc-sdk.astraprotocol.co
1938
2041
  const [qrUrl, setQrUrl] = useState("");
1939
2042
  const [copied, setCopied] = useState(false);
1940
2043
  useEffect(() => {
1941
- const searchParams = new URLSearchParams(window.location.search);
1942
- if (sessionId) {
1943
- searchParams.set("sessionId", sessionId);
1944
- }
1945
- if (apiBaseUrl) {
1946
- searchParams.set("apiBaseUrl", apiBaseUrl);
2044
+ if (sessionId && apiBaseUrl && serverKey) {
2045
+ storeKycConfig(sessionId, apiBaseUrl, serverKey);
1947
2046
  }
1948
- if (serverKey) {
1949
- searchParams.set("serverKey", serverKey);
2047
+ if (sessionId && apiBaseUrl && serverKey) {
2048
+ const mobileRoute = "/mobileroute";
2049
+ const config = JSON.stringify({ apiBaseUrl, serverKey });
2050
+ const encodedConfig = btoa(config);
2051
+ const fullUrl = `${mobileBaseUrl}${mobileRoute}?sessionId=${sessionId}&config=${encodedConfig}`;
2052
+ setQrUrl(fullUrl);
2053
+ } else if (sessionId) {
2054
+ const mobileRoute = "/mobileroute";
2055
+ const fullUrl = `${mobileBaseUrl}${mobileRoute}?sessionId=${sessionId}`;
2056
+ setQrUrl(fullUrl);
1950
2057
  }
1951
- const mobileRoute = "/mobileroute";
1952
- const queryString = searchParams.toString();
1953
- const fullUrl = `${mobileBaseUrl}${mobileRoute}${queryString ? `?${queryString}` : ""}`;
1954
- setQrUrl(fullUrl);
1955
2058
  }, [mobileBaseUrl, sessionId, apiBaseUrl, serverKey]);
1956
2059
  const handleCopyUrl = async () => {
1957
2060
  if (qrUrl) {