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.
- package/dist/astra-sdk.cjs.js +106 -23
- package/dist/astra-sdk.cjs.js.map +1 -1
- package/dist/astra-sdk.es.js +106 -23
- package/dist/astra-sdk.es.js.map +1 -1
- package/dist/components.cjs.js +106 -23
- package/dist/components.cjs.js.map +1 -1
- package/dist/components.es.js +106 -23
- package/dist/components.es.js.map +1 -1
- package/package.json +1 -1
- package/src/pages/MobileRoute.tsx +33 -14
- package/src/pages/QRCodePage.tsx +10 -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,36 @@ 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
|
+
const storedConfig = getKycConfig(sessionId);
|
|
1768
|
+
if (storedConfig) {
|
|
1769
|
+
setConfig({
|
|
1770
|
+
apiBaseUrl: storedConfig.apiBaseUrl,
|
|
1771
|
+
sessionId,
|
|
1772
|
+
serverKey: storedConfig.serverKey
|
|
1773
|
+
});
|
|
1774
|
+
} else {
|
|
1775
|
+
const apiBaseUrl = searchParams.get("apiBaseUrl") || searchParams.get("apiUrl") || "";
|
|
1776
|
+
const serverKey = searchParams.get("serverKey") || "";
|
|
1777
|
+
if (apiBaseUrl && serverKey) {
|
|
1778
|
+
setConfig({
|
|
1779
|
+
apiBaseUrl,
|
|
1780
|
+
sessionId,
|
|
1781
|
+
serverKey
|
|
1782
|
+
});
|
|
1783
|
+
} else {
|
|
1784
|
+
console.error("Missing required parameters: apiBaseUrl and serverKey not found in localStorage or URL");
|
|
1785
|
+
}
|
|
1786
|
+
}
|
|
1787
|
+
} else {
|
|
1788
|
+
console.error("Missing required parameter: sessionId must be in URL");
|
|
1700
1789
|
}
|
|
1701
1790
|
}, [onNavigate]);
|
|
1702
1791
|
const handleClose = () => {
|
|
@@ -1727,7 +1816,7 @@ function MobileRoute({ onClose, onNavigate } = {}) {
|
|
|
1727
1816
|
}
|
|
1728
1817
|
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
1818
|
/* @__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
|
|
1819
|
+
/* @__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
1820
|
] }) });
|
|
1732
1821
|
}
|
|
1733
1822
|
var MobileRoute_default = MobileRoute;
|
|
@@ -1735,20 +1824,14 @@ function QRCodePage({ onClose, mobileBaseUrl = "https://kyc-sdk.astraprotocol.co
|
|
|
1735
1824
|
const [qrUrl, setQrUrl] = useState("");
|
|
1736
1825
|
const [copied, setCopied] = useState(false);
|
|
1737
1826
|
useEffect(() => {
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
searchParams.set("sessionId", sessionId);
|
|
1741
|
-
}
|
|
1742
|
-
if (apiBaseUrl) {
|
|
1743
|
-
searchParams.set("apiBaseUrl", apiBaseUrl);
|
|
1827
|
+
if (sessionId && apiBaseUrl && serverKey) {
|
|
1828
|
+
storeKycConfig(sessionId, apiBaseUrl, serverKey);
|
|
1744
1829
|
}
|
|
1745
|
-
if (
|
|
1746
|
-
|
|
1830
|
+
if (sessionId) {
|
|
1831
|
+
const mobileRoute = "/mobileroute";
|
|
1832
|
+
const fullUrl = `${mobileBaseUrl}${mobileRoute}?sessionId=${sessionId}`;
|
|
1833
|
+
setQrUrl(fullUrl);
|
|
1747
1834
|
}
|
|
1748
|
-
const mobileRoute = "/mobileroute";
|
|
1749
|
-
const queryString = searchParams.toString();
|
|
1750
|
-
const fullUrl = `${mobileBaseUrl}${mobileRoute}${queryString ? `?${queryString}` : ""}`;
|
|
1751
|
-
setQrUrl(fullUrl);
|
|
1752
1835
|
}, [mobileBaseUrl, sessionId, apiBaseUrl, serverKey]);
|
|
1753
1836
|
const handleCopyUrl = async () => {
|
|
1754
1837
|
if (qrUrl) {
|