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.cjs.js
CHANGED
|
@@ -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,50 @@ 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
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1772
|
+
if (sessionId) {
|
|
1773
|
+
let apiBaseUrl = "";
|
|
1774
|
+
let serverKey = "";
|
|
1775
|
+
const encodedConfig = searchParams.get("config");
|
|
1776
|
+
if (encodedConfig) {
|
|
1777
|
+
try {
|
|
1778
|
+
const decodedConfig = JSON.parse(atob(encodedConfig));
|
|
1779
|
+
if (decodedConfig.apiBaseUrl && decodedConfig.serverKey) {
|
|
1780
|
+
apiBaseUrl = decodedConfig.apiBaseUrl;
|
|
1781
|
+
serverKey = decodedConfig.serverKey;
|
|
1782
|
+
}
|
|
1783
|
+
} catch (error) {
|
|
1784
|
+
console.error("Failed to decode config from URL:", error);
|
|
1785
|
+
}
|
|
1786
|
+
}
|
|
1787
|
+
if (!apiBaseUrl || !serverKey) {
|
|
1788
|
+
const storedConfig = getKycConfig(sessionId);
|
|
1789
|
+
if (storedConfig) {
|
|
1790
|
+
apiBaseUrl = storedConfig.apiBaseUrl;
|
|
1791
|
+
serverKey = storedConfig.serverKey;
|
|
1792
|
+
}
|
|
1793
|
+
}
|
|
1794
|
+
if (!apiBaseUrl || !serverKey) {
|
|
1795
|
+
apiBaseUrl = searchParams.get("apiBaseUrl") || searchParams.get("apiUrl") || "";
|
|
1796
|
+
serverKey = searchParams.get("serverKey") || "";
|
|
1797
|
+
}
|
|
1798
|
+
if (apiBaseUrl && serverKey) {
|
|
1799
|
+
setConfig({
|
|
1800
|
+
apiBaseUrl,
|
|
1801
|
+
sessionId,
|
|
1802
|
+
serverKey
|
|
1803
|
+
});
|
|
1804
|
+
} else {
|
|
1805
|
+
console.error("Missing required parameters: apiBaseUrl and serverKey not found in URL config, localStorage, or URL params");
|
|
1806
|
+
}
|
|
1807
|
+
} else {
|
|
1808
|
+
console.error("Missing required parameter: sessionId must be in URL");
|
|
1706
1809
|
}
|
|
1707
1810
|
}, [onNavigate]);
|
|
1708
1811
|
const handleClose = () => {
|
|
@@ -1733,7 +1836,7 @@ function MobileRoute({ onClose, onNavigate } = {}) {
|
|
|
1733
1836
|
}
|
|
1734
1837
|
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
1838
|
/* @__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
|
|
1839
|
+
/* @__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
1840
|
] }) });
|
|
1738
1841
|
}
|
|
1739
1842
|
var MobileRoute_default = MobileRoute;
|
|
@@ -1741,20 +1844,20 @@ function QRCodePage({ onClose, mobileBaseUrl = "https://kyc-sdk.astraprotocol.co
|
|
|
1741
1844
|
const [qrUrl, setQrUrl] = React.useState("");
|
|
1742
1845
|
const [copied, setCopied] = React.useState(false);
|
|
1743
1846
|
React.useEffect(() => {
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
searchParams.set("sessionId", sessionId);
|
|
1747
|
-
}
|
|
1748
|
-
if (apiBaseUrl) {
|
|
1749
|
-
searchParams.set("apiBaseUrl", apiBaseUrl);
|
|
1847
|
+
if (sessionId && apiBaseUrl && serverKey) {
|
|
1848
|
+
storeKycConfig(sessionId, apiBaseUrl, serverKey);
|
|
1750
1849
|
}
|
|
1751
|
-
if (serverKey) {
|
|
1752
|
-
|
|
1850
|
+
if (sessionId && apiBaseUrl && serverKey) {
|
|
1851
|
+
const mobileRoute = "/mobileroute";
|
|
1852
|
+
const config = JSON.stringify({ apiBaseUrl, serverKey });
|
|
1853
|
+
const encodedConfig = btoa(config);
|
|
1854
|
+
const fullUrl = `${mobileBaseUrl}${mobileRoute}?sessionId=${sessionId}&config=${encodedConfig}`;
|
|
1855
|
+
setQrUrl(fullUrl);
|
|
1856
|
+
} else if (sessionId) {
|
|
1857
|
+
const mobileRoute = "/mobileroute";
|
|
1858
|
+
const fullUrl = `${mobileBaseUrl}${mobileRoute}?sessionId=${sessionId}`;
|
|
1859
|
+
setQrUrl(fullUrl);
|
|
1753
1860
|
}
|
|
1754
|
-
const mobileRoute = "/mobileroute";
|
|
1755
|
-
const queryString = searchParams.toString();
|
|
1756
|
-
const fullUrl = `${mobileBaseUrl}${mobileRoute}${queryString ? `?${queryString}` : ""}`;
|
|
1757
|
-
setQrUrl(fullUrl);
|
|
1758
1861
|
}, [mobileBaseUrl, sessionId, apiBaseUrl, serverKey]);
|
|
1759
1862
|
const handleCopyUrl = async () => {
|
|
1760
1863
|
if (qrUrl) {
|