astra-sdk-web 1.1.28 → 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 -106
- package/dist/astra-sdk.cjs.js.map +1 -1
- package/dist/astra-sdk.css.map +1 -1
- package/dist/astra-sdk.es.js +23 -106
- package/dist/astra-sdk.es.js.map +1 -1
- package/dist/components.cjs.js +23 -106
- package/dist/components.cjs.js.map +1 -1
- package/dist/components.css.map +1 -1
- package/dist/components.es.js +23 -106
- package/dist/components.es.js.map +1 -1
- package/package.json +1 -1
- package/src/index.css +0 -5
- package/src/pages/MobileRoute.tsx +14 -33
- package/src/pages/QRCodePage.tsx +17 -10
- 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,45 +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');
|
|
33
|
+
const apiBaseUrl = searchParams.get('apiBaseUrl') || searchParams.get('apiUrl') || '';
|
|
34
|
+
const serverKey = searchParams.get('serverKey') || '';
|
|
37
35
|
|
|
38
|
-
if (sessionId) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
} else {
|
|
49
|
-
// Fallback: try to get from URL params (for backward compatibility)
|
|
50
|
-
const apiBaseUrl = searchParams.get('apiBaseUrl') || searchParams.get('apiUrl') || '';
|
|
51
|
-
const serverKey = searchParams.get('serverKey') || '';
|
|
52
|
-
|
|
53
|
-
if (apiBaseUrl && serverKey) {
|
|
54
|
-
setConfig({
|
|
55
|
-
apiBaseUrl,
|
|
56
|
-
sessionId,
|
|
57
|
-
serverKey,
|
|
58
|
-
});
|
|
59
|
-
} else {
|
|
60
|
-
console.error('Missing required parameters: apiBaseUrl and serverKey not found in localStorage or URL');
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
} else {
|
|
64
|
-
console.error('Missing required parameter: sessionId must be in URL');
|
|
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');
|
|
65
46
|
}
|
|
66
47
|
}, [onNavigate]);
|
|
67
48
|
|
|
@@ -109,7 +90,7 @@ function MobileRoute({ onClose, onNavigate }: MobileRouteProps = {}) {
|
|
|
109
90
|
<div className="bg-white p-6 rounded-lg text-center max-w-md mx-4">
|
|
110
91
|
<p className="text-red-600 mb-2">Missing Configuration</p>
|
|
111
92
|
<p className="text-sm text-gray-600">
|
|
112
|
-
Please ensure the URL includes sessionId
|
|
93
|
+
Please ensure the URL includes sessionId, apiBaseUrl, and serverKey parameters.
|
|
113
94
|
</p>
|
|
114
95
|
</div>
|
|
115
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,17 +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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
// Only include sessionId in URL, not apiBaseUrl or serverKey
|
|
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
|
|
31
28
|
if (sessionId) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
searchParams.set('sessionId', sessionId);
|
|
30
|
+
}
|
|
31
|
+
if (apiBaseUrl) {
|
|
32
|
+
searchParams.set('apiBaseUrl', apiBaseUrl);
|
|
35
33
|
}
|
|
34
|
+
if (serverKey) {
|
|
35
|
+
searchParams.set('serverKey', serverKey);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const mobileRoute = '/mobileroute';
|
|
39
|
+
const queryString = searchParams.toString();
|
|
40
|
+
const fullUrl = `${mobileBaseUrl}${mobileRoute}${queryString ? `?${queryString}` : ''}`;
|
|
41
|
+
|
|
42
|
+
setQrUrl(fullUrl);
|
|
36
43
|
}, [mobileBaseUrl, sessionId, apiBaseUrl, serverKey]);
|
|
37
44
|
|
|
38
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
|
-
|