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