astra-sdk-web 1.1.29 → 1.1.30
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 +23 -126
- package/dist/astra-sdk.cjs.js.map +1 -1
- package/dist/astra-sdk.css.map +1 -1
- package/dist/astra-sdk.es.js +23 -126
- package/dist/astra-sdk.es.js.map +1 -1
- package/dist/components.cjs.js +23 -126
- package/dist/components.cjs.js.map +1 -1
- package/dist/components.css.map +1 -1
- package/dist/components.es.js +23 -126
- package/dist/components.es.js.map +1 -1
- package/package.json +1 -1
- package/src/index.css +0 -5
- package/src/pages/MobileRoute.tsx +15 -51
- package/src/pages/QRCodePage.tsx +17 -18
- package/src/utils/kycConfigStorage.ts +0 -125
package/package.json
CHANGED
package/src/index.css
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react';
|
|
2
2
|
import { isMobileDevice } from '../utils/deviceDetection';
|
|
3
|
-
import { getKycConfig, clearExpiredConfigs } from '../utils/kycConfigStorage';
|
|
4
3
|
import FaceScanModal from './FaceScanModal';
|
|
5
4
|
import { KycProvider } from '../contexts/KycContext';
|
|
6
5
|
import '../index.css';
|
|
@@ -23,62 +22,27 @@ function MobileRoute({ onClose, onNavigate }: MobileRouteProps = {}) {
|
|
|
23
22
|
} | null>(null);
|
|
24
23
|
|
|
25
24
|
useEffect(() => {
|
|
26
|
-
// Clear expired configs on mount
|
|
27
|
-
clearExpiredConfigs();
|
|
28
|
-
|
|
29
25
|
if (!isMobileDevice() && onNavigate) {
|
|
30
26
|
onNavigate('qr');
|
|
31
27
|
return;
|
|
32
28
|
}
|
|
33
29
|
|
|
34
|
-
//
|
|
30
|
+
// If accessed standalone (via URL), get config from URL params
|
|
35
31
|
const searchParams = new URLSearchParams(window.location.search);
|
|
36
32
|
const sessionId = searchParams.get('sessionId');
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
} catch (error) {
|
|
52
|
-
console.error('Failed to decode config from URL:', error);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// If not found in encoded config, try localStorage (for same-device scenarios)
|
|
57
|
-
if (!apiBaseUrl || !serverKey) {
|
|
58
|
-
const storedConfig = getKycConfig(sessionId);
|
|
59
|
-
if (storedConfig) {
|
|
60
|
-
apiBaseUrl = storedConfig.apiBaseUrl;
|
|
61
|
-
serverKey = storedConfig.serverKey;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Fallback: try to get from URL params directly (for backward compatibility)
|
|
66
|
-
if (!apiBaseUrl || !serverKey) {
|
|
67
|
-
apiBaseUrl = searchParams.get('apiBaseUrl') || searchParams.get('apiUrl') || '';
|
|
68
|
-
serverKey = searchParams.get('serverKey') || '';
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (apiBaseUrl && serverKey) {
|
|
72
|
-
setConfig({
|
|
73
|
-
apiBaseUrl,
|
|
74
|
-
sessionId,
|
|
75
|
-
serverKey,
|
|
76
|
-
});
|
|
77
|
-
} else {
|
|
78
|
-
console.error('Missing required parameters: apiBaseUrl and serverKey not found in URL config, localStorage, or URL params');
|
|
79
|
-
}
|
|
80
|
-
} else {
|
|
81
|
-
console.error('Missing required parameter: sessionId must be in URL');
|
|
33
|
+
const apiBaseUrl = searchParams.get('apiBaseUrl') || searchParams.get('apiUrl') || '';
|
|
34
|
+
const serverKey = searchParams.get('serverKey') || '';
|
|
35
|
+
|
|
36
|
+
if (sessionId && apiBaseUrl && serverKey) {
|
|
37
|
+
setConfig({
|
|
38
|
+
apiBaseUrl,
|
|
39
|
+
sessionId,
|
|
40
|
+
serverKey,
|
|
41
|
+
});
|
|
42
|
+
} else if (sessionId) {
|
|
43
|
+
// Try to get from localStorage or use defaults
|
|
44
|
+
// For now, we'll need these to be passed via URL
|
|
45
|
+
console.error('Missing required parameters: apiBaseUrl and serverKey must be in URL');
|
|
82
46
|
}
|
|
83
47
|
}, [onNavigate]);
|
|
84
48
|
|
|
@@ -126,7 +90,7 @@ function MobileRoute({ onClose, onNavigate }: MobileRouteProps = {}) {
|
|
|
126
90
|
<div className="bg-white p-6 rounded-lg text-center max-w-md mx-4">
|
|
127
91
|
<p className="text-red-600 mb-2">Missing Configuration</p>
|
|
128
92
|
<p className="text-sm text-gray-600">
|
|
129
|
-
Please ensure the URL includes sessionId
|
|
93
|
+
Please ensure the URL includes sessionId, apiBaseUrl, and serverKey parameters.
|
|
130
94
|
</p>
|
|
131
95
|
</div>
|
|
132
96
|
</div>
|
package/src/pages/QRCodePage.tsx
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { useState, useEffect } from 'react';
|
|
2
2
|
import { QRCodeSVG } from 'qrcode.react';
|
|
3
3
|
import { KycApiService } from '../services/kycApiService';
|
|
4
|
-
import { storeKycConfig } from '../utils/kycConfigStorage';
|
|
5
4
|
// @ts-ignore - optional dependency, may not be installed in some consumers
|
|
6
5
|
import { toast, ToastContainer } from 'react-toastify';
|
|
7
6
|
// @ts-ignore - import styles only when package is present
|
|
@@ -22,25 +21,25 @@ function QRCodePage({ onClose, mobileBaseUrl = 'https://kyc-sdk.astraprotocol.co
|
|
|
22
21
|
const [copied, setCopied] = useState<boolean>(false);
|
|
23
22
|
|
|
24
23
|
useEffect(() => {
|
|
25
|
-
//
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
// Get search params from current URL
|
|
25
|
+
const searchParams = new URLSearchParams(window.location.search);
|
|
26
|
+
|
|
27
|
+
// Add required params to query string for mobile route
|
|
28
|
+
if (sessionId) {
|
|
29
|
+
searchParams.set('sessionId', sessionId);
|
|
28
30
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const config = JSON.stringify({ apiBaseUrl, serverKey });
|
|
35
|
-
const encodedConfig = btoa(config);
|
|
36
|
-
const fullUrl = `${mobileBaseUrl}${mobileRoute}?sessionId=${sessionId}&config=${encodedConfig}`;
|
|
37
|
-
setQrUrl(fullUrl);
|
|
38
|
-
} else if (sessionId) {
|
|
39
|
-
// Fallback: just sessionId if config not available
|
|
40
|
-
const mobileRoute = '/mobileroute';
|
|
41
|
-
const fullUrl = `${mobileBaseUrl}${mobileRoute}?sessionId=${sessionId}`;
|
|
42
|
-
setQrUrl(fullUrl);
|
|
31
|
+
if (apiBaseUrl) {
|
|
32
|
+
searchParams.set('apiBaseUrl', apiBaseUrl);
|
|
33
|
+
}
|
|
34
|
+
if (serverKey) {
|
|
35
|
+
searchParams.set('serverKey', serverKey);
|
|
43
36
|
}
|
|
37
|
+
|
|
38
|
+
const mobileRoute = '/mobileroute';
|
|
39
|
+
const queryString = searchParams.toString();
|
|
40
|
+
const fullUrl = `${mobileBaseUrl}${mobileRoute}${queryString ? `?${queryString}` : ''}`;
|
|
41
|
+
|
|
42
|
+
setQrUrl(fullUrl);
|
|
44
43
|
}, [mobileBaseUrl, sessionId, apiBaseUrl, serverKey]);
|
|
45
44
|
|
|
46
45
|
const handleCopyUrl = async () => {
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Utility functions for storing and retrieving KYC configuration
|
|
3
|
-
* Uses localStorage to store apiBaseUrl and serverKey associated with sessionId
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
interface KycConfig {
|
|
7
|
-
apiBaseUrl: string;
|
|
8
|
-
serverKey: string;
|
|
9
|
-
sessionId: string;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const STORAGE_PREFIX = 'kyc_config_';
|
|
13
|
-
const STORAGE_EXPIRY_MS = 24 * 60 * 60 * 1000; // 24 hours
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Store KYC configuration in localStorage
|
|
17
|
-
*/
|
|
18
|
-
export function storeKycConfig(sessionId: string, apiBaseUrl: string, serverKey: string): void {
|
|
19
|
-
if (!sessionId || !apiBaseUrl || !serverKey) {
|
|
20
|
-
console.warn('Cannot store KYC config: missing required parameters');
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
try {
|
|
25
|
-
const config: KycConfig = {
|
|
26
|
-
apiBaseUrl,
|
|
27
|
-
serverKey,
|
|
28
|
-
sessionId,
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const storageKey = `${STORAGE_PREFIX}${sessionId}`;
|
|
32
|
-
const data = {
|
|
33
|
-
config,
|
|
34
|
-
timestamp: Date.now(),
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
localStorage.setItem(storageKey, JSON.stringify(data));
|
|
38
|
-
} catch (error) {
|
|
39
|
-
console.error('Failed to store KYC config:', error);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Retrieve KYC configuration from localStorage
|
|
45
|
-
*/
|
|
46
|
-
export function getKycConfig(sessionId: string): { apiBaseUrl: string; serverKey: string } | null {
|
|
47
|
-
if (!sessionId) {
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
try {
|
|
52
|
-
const storageKey = `${STORAGE_PREFIX}${sessionId}`;
|
|
53
|
-
const stored = localStorage.getItem(storageKey);
|
|
54
|
-
|
|
55
|
-
if (!stored) {
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const data = JSON.parse(stored);
|
|
60
|
-
|
|
61
|
-
// Check if config is expired
|
|
62
|
-
if (data.timestamp && Date.now() - data.timestamp > STORAGE_EXPIRY_MS) {
|
|
63
|
-
localStorage.removeItem(storageKey);
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (data.config && data.config.apiBaseUrl && data.config.serverKey) {
|
|
68
|
-
return {
|
|
69
|
-
apiBaseUrl: data.config.apiBaseUrl,
|
|
70
|
-
serverKey: data.config.serverKey,
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return null;
|
|
75
|
-
} catch (error) {
|
|
76
|
-
console.error('Failed to retrieve KYC config:', error);
|
|
77
|
-
return null;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Clear KYC configuration from localStorage
|
|
83
|
-
*/
|
|
84
|
-
export function clearKycConfig(sessionId: string): void {
|
|
85
|
-
if (!sessionId) {
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
try {
|
|
90
|
-
const storageKey = `${STORAGE_PREFIX}${sessionId}`;
|
|
91
|
-
localStorage.removeItem(storageKey);
|
|
92
|
-
} catch (error) {
|
|
93
|
-
console.error('Failed to clear KYC config:', error);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Clear all expired KYC configurations
|
|
99
|
-
*/
|
|
100
|
-
export function clearExpiredConfigs(): void {
|
|
101
|
-
try {
|
|
102
|
-
const keys = Object.keys(localStorage);
|
|
103
|
-
const now = Date.now();
|
|
104
|
-
|
|
105
|
-
keys.forEach((key) => {
|
|
106
|
-
if (key.startsWith(STORAGE_PREFIX)) {
|
|
107
|
-
try {
|
|
108
|
-
const stored = localStorage.getItem(key);
|
|
109
|
-
if (stored) {
|
|
110
|
-
const data = JSON.parse(stored);
|
|
111
|
-
if (data.timestamp && now - data.timestamp > STORAGE_EXPIRY_MS) {
|
|
112
|
-
localStorage.removeItem(key);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
} catch (error) {
|
|
116
|
-
// If parsing fails, remove the key
|
|
117
|
-
localStorage.removeItem(key);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
} catch (error) {
|
|
122
|
-
console.error('Failed to clear expired configs:', error);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|