astra-sdk-web 1.1.26 → 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 +108 -25
- package/dist/astra-sdk.cjs.js.map +1 -1
- package/dist/astra-sdk.css +0 -3
- package/dist/astra-sdk.css.map +1 -1
- package/dist/astra-sdk.es.js +108 -25
- package/dist/astra-sdk.es.js.map +1 -1
- package/dist/components.cjs.js +108 -25
- package/dist/components.cjs.js.map +1 -1
- package/dist/components.css +0 -3
- package/dist/components.css.map +1 -1
- package/dist/components.es.js +108 -25
- 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 +12 -19
- 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,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
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
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
|
|
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
|
-
|
|
1745
|
-
|
|
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 (
|
|
1752
|
-
|
|
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) {
|
|
@@ -1796,7 +1879,7 @@ function QRCodePage({ onClose, mobileBaseUrl = "https://kyc-sdk.astraprotocol.co
|
|
|
1796
1879
|
backgroundImage: `radial-gradient(circle at 2px 2px, rgba(255,255,255,0.15) 1px, transparent 0)`,
|
|
1797
1880
|
backgroundSize: "40px 40px"
|
|
1798
1881
|
} }),
|
|
1799
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "relative bg-[rgba(20,20,20,0.95)] backdrop-blur-sm rounded-2xl p-5 sm:p-6 md:p-7 max-w-[450px] w-full h-[80vh] flex flex-col text-center shadow-[0_8px_32px_rgba(0,0,0,0.5)]
|
|
1882
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "relative bg-[rgba(20,20,20,0.95)] backdrop-blur-sm rounded-2xl p-5 sm:p-6 md:p-7 max-w-[450px] w-full h-[80vh] flex flex-col text-center shadow-[0_8px_32px_rgba(0,0,0,0.5)]", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col items-center gap-3 sm:gap-4 flex-1 overflow-y-auto custom__scrollbar", children: [
|
|
1800
1883
|
/* @__PURE__ */ jsxRuntime.jsx("h1", { className: "m-0 text-white text-xl sm:text-2xl font-semibold leading-tight", children: "Continue on Mobile" }),
|
|
1801
1884
|
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "m-0 text-white text-sm sm:text-base opacity-90 leading-relaxed", children: "Scan this QR on your phone to capture your face and document" }),
|
|
1802
1885
|
qrUrl && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center items-center p-3 sm:p-4 bg-black rounded-xl border-2 border-white shadow-lg", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -1813,7 +1896,7 @@ function QRCodePage({ onClose, mobileBaseUrl = "https://kyc-sdk.astraprotocol.co
|
|
|
1813
1896
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full text-left mt-auto", children: [
|
|
1814
1897
|
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "m-0 mb-2 text-white text-xs sm:text-sm opacity-80", children: "Or open:" }),
|
|
1815
1898
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col sm:flex-row items-start sm:items-center gap-2 p-2 sm:p-3 bg-white/10 rounded-lg border border-white/20", children: [
|
|
1816
|
-
/* @__PURE__ */ jsxRuntime.jsx("code", { className: "flex-1 text-white text-xs sm:text-sm break-all text-left m-0 font-mono line-clamp-1", children: qrUrl }),
|
|
1899
|
+
/* @__PURE__ */ jsxRuntime.jsx("code", { className: "flex-1 text-white text-xs sm:text-sm break-all text-left m-0 font-mono line-clamp-1 ", children: qrUrl }),
|
|
1817
1900
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1818
1901
|
"button",
|
|
1819
1902
|
{
|