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.
@@ -280,6 +280,81 @@ function isMobileDevice() {
280
280
  const hasTouchScreen = "ontouchstart" in window || navigator.maxTouchPoints > 0;
281
281
  return mobileRegex.test(userAgent) || isSmallScreen && hasTouchScreen;
282
282
  }
283
+
284
+ // src/utils/kycConfigStorage.ts
285
+ var STORAGE_PREFIX = "kyc_config_";
286
+ var STORAGE_EXPIRY_MS = 24 * 60 * 60 * 1e3;
287
+ function storeKycConfig(sessionId, apiBaseUrl, serverKey) {
288
+ if (!sessionId || !apiBaseUrl || !serverKey) {
289
+ console.warn("Cannot store KYC config: missing required parameters");
290
+ return;
291
+ }
292
+ try {
293
+ const config = {
294
+ apiBaseUrl,
295
+ serverKey,
296
+ sessionId
297
+ };
298
+ const storageKey = `${STORAGE_PREFIX}${sessionId}`;
299
+ const data = {
300
+ config,
301
+ timestamp: Date.now()
302
+ };
303
+ localStorage.setItem(storageKey, JSON.stringify(data));
304
+ } catch (error) {
305
+ console.error("Failed to store KYC config:", error);
306
+ }
307
+ }
308
+ function getKycConfig(sessionId) {
309
+ if (!sessionId) {
310
+ return null;
311
+ }
312
+ try {
313
+ const storageKey = `${STORAGE_PREFIX}${sessionId}`;
314
+ const stored = localStorage.getItem(storageKey);
315
+ if (!stored) {
316
+ return null;
317
+ }
318
+ const data = JSON.parse(stored);
319
+ if (data.timestamp && Date.now() - data.timestamp > STORAGE_EXPIRY_MS) {
320
+ localStorage.removeItem(storageKey);
321
+ return null;
322
+ }
323
+ if (data.config && data.config.apiBaseUrl && data.config.serverKey) {
324
+ return {
325
+ apiBaseUrl: data.config.apiBaseUrl,
326
+ serverKey: data.config.serverKey
327
+ };
328
+ }
329
+ return null;
330
+ } catch (error) {
331
+ console.error("Failed to retrieve KYC config:", error);
332
+ return null;
333
+ }
334
+ }
335
+ function clearExpiredConfigs() {
336
+ try {
337
+ const keys = Object.keys(localStorage);
338
+ const now = Date.now();
339
+ keys.forEach((key) => {
340
+ if (key.startsWith(STORAGE_PREFIX)) {
341
+ try {
342
+ const stored = localStorage.getItem(key);
343
+ if (stored) {
344
+ const data = JSON.parse(stored);
345
+ if (data.timestamp && now - data.timestamp > STORAGE_EXPIRY_MS) {
346
+ localStorage.removeItem(key);
347
+ }
348
+ }
349
+ } catch (error) {
350
+ localStorage.removeItem(key);
351
+ }
352
+ }
353
+ });
354
+ } catch (error) {
355
+ console.error("Failed to clear expired configs:", error);
356
+ }
357
+ }
283
358
  function useDocumentUpload(callbacks) {
284
359
  const [state, setState] = React.useState({
285
360
  docType: "CNIC",
@@ -1687,22 +1762,36 @@ function MobileRouteContent({ onClose, onComplete }) {
1687
1762
  function MobileRoute({ onClose, onNavigate } = {}) {
1688
1763
  const [config, setConfig] = React.useState(null);
1689
1764
  React.useEffect(() => {
1765
+ clearExpiredConfigs();
1690
1766
  if (!isMobileDevice() && onNavigate) {
1691
1767
  onNavigate("qr");
1692
1768
  return;
1693
1769
  }
1694
1770
  const searchParams = new URLSearchParams(window.location.search);
1695
1771
  const sessionId = searchParams.get("sessionId");
1696
- const apiBaseUrl = searchParams.get("apiBaseUrl") || searchParams.get("apiUrl") || "";
1697
- const serverKey = searchParams.get("serverKey") || "";
1698
- if (sessionId && apiBaseUrl && serverKey) {
1699
- setConfig({
1700
- apiBaseUrl,
1701
- sessionId,
1702
- serverKey
1703
- });
1704
- } else if (sessionId) {
1705
- console.error("Missing required parameters: apiBaseUrl and serverKey must be in URL");
1772
+ if (sessionId) {
1773
+ const storedConfig = getKycConfig(sessionId);
1774
+ if (storedConfig) {
1775
+ setConfig({
1776
+ apiBaseUrl: storedConfig.apiBaseUrl,
1777
+ sessionId,
1778
+ serverKey: storedConfig.serverKey
1779
+ });
1780
+ } else {
1781
+ const apiBaseUrl = searchParams.get("apiBaseUrl") || searchParams.get("apiUrl") || "";
1782
+ const serverKey = searchParams.get("serverKey") || "";
1783
+ if (apiBaseUrl && serverKey) {
1784
+ setConfig({
1785
+ apiBaseUrl,
1786
+ sessionId,
1787
+ serverKey
1788
+ });
1789
+ } else {
1790
+ console.error("Missing required parameters: apiBaseUrl and serverKey not found in localStorage or URL");
1791
+ }
1792
+ }
1793
+ } else {
1794
+ console.error("Missing required parameter: sessionId must be in URL");
1706
1795
  }
1707
1796
  }, [onNavigate]);
1708
1797
  const handleClose = () => {
@@ -1733,7 +1822,7 @@ function MobileRoute({ onClose, onNavigate } = {}) {
1733
1822
  }
1734
1823
  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: [
1735
1824
  /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-red-600 mb-2", children: "Missing Configuration" }),
1736
- /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-gray-600", children: "Please ensure the URL includes sessionId, apiBaseUrl, and serverKey parameters." })
1825
+ /* @__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." })
1737
1826
  ] }) });
1738
1827
  }
1739
1828
  var MobileRoute_default = MobileRoute;
@@ -1741,20 +1830,14 @@ function QRCodePage({ onClose, mobileBaseUrl = "https://kyc-sdk.astraprotocol.co
1741
1830
  const [qrUrl, setQrUrl] = React.useState("");
1742
1831
  const [copied, setCopied] = React.useState(false);
1743
1832
  React.useEffect(() => {
1744
- const searchParams = new URLSearchParams(window.location.search);
1745
- if (sessionId) {
1746
- searchParams.set("sessionId", sessionId);
1747
- }
1748
- if (apiBaseUrl) {
1749
- searchParams.set("apiBaseUrl", apiBaseUrl);
1833
+ if (sessionId && apiBaseUrl && serverKey) {
1834
+ storeKycConfig(sessionId, apiBaseUrl, serverKey);
1750
1835
  }
1751
- if (serverKey) {
1752
- searchParams.set("serverKey", serverKey);
1836
+ if (sessionId) {
1837
+ const mobileRoute = "/mobileroute";
1838
+ const fullUrl = `${mobileBaseUrl}${mobileRoute}?sessionId=${sessionId}`;
1839
+ setQrUrl(fullUrl);
1753
1840
  }
1754
- const mobileRoute = "/mobileroute";
1755
- const queryString = searchParams.toString();
1756
- const fullUrl = `${mobileBaseUrl}${mobileRoute}${queryString ? `?${queryString}` : ""}`;
1757
- setQrUrl(fullUrl);
1758
1841
  }, [mobileBaseUrl, sessionId, apiBaseUrl, serverKey]);
1759
1842
  const handleCopyUrl = async () => {
1760
1843
  if (qrUrl) {