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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astra-sdk-web",
3
- "version": "1.1.26",
3
+ "version": "1.1.28",
4
4
  "description": "Official Astra SDK for JavaScript/TypeScript",
5
5
  "type": "module",
6
6
  "main": "./dist/astra-sdk.cjs.js",
@@ -1,5 +1,6 @@
1
1
  import { useEffect, useState } from 'react';
2
2
  import { isMobileDevice } from '../utils/deviceDetection';
3
+ import { getKycConfig, clearExpiredConfigs } from '../utils/kycConfigStorage';
3
4
  import FaceScanModal from './FaceScanModal';
4
5
  import { KycProvider } from '../contexts/KycContext';
5
6
  import '../index.css';
@@ -22,27 +23,45 @@ function MobileRoute({ onClose, onNavigate }: MobileRouteProps = {}) {
22
23
  } | null>(null);
23
24
 
24
25
  useEffect(() => {
26
+ // Clear expired configs on mount
27
+ clearExpiredConfigs();
28
+
25
29
  if (!isMobileDevice() && onNavigate) {
26
30
  onNavigate('qr');
27
31
  return;
28
32
  }
29
33
 
30
- // If accessed standalone (via URL), get config from URL params
34
+ // Get sessionId from URL params
31
35
  const searchParams = new URLSearchParams(window.location.search);
32
36
  const sessionId = searchParams.get('sessionId');
33
- const apiBaseUrl = searchParams.get('apiBaseUrl') || searchParams.get('apiUrl') || '';
34
- const serverKey = searchParams.get('serverKey') || '';
35
37
 
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');
38
+ if (sessionId) {
39
+ // Try to get apiBaseUrl and serverKey from localStorage
40
+ const storedConfig = getKycConfig(sessionId);
41
+
42
+ if (storedConfig) {
43
+ setConfig({
44
+ apiBaseUrl: storedConfig.apiBaseUrl,
45
+ sessionId,
46
+ serverKey: storedConfig.serverKey,
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');
46
65
  }
47
66
  }, [onNavigate]);
48
67
 
@@ -90,7 +109,7 @@ function MobileRoute({ onClose, onNavigate }: MobileRouteProps = {}) {
90
109
  <div className="bg-white p-6 rounded-lg text-center max-w-md mx-4">
91
110
  <p className="text-red-600 mb-2">Missing Configuration</p>
92
111
  <p className="text-sm text-gray-600">
93
- Please ensure the URL includes sessionId, apiBaseUrl, and serverKey parameters.
112
+ Please ensure the URL includes sessionId parameter. The configuration should be stored automatically when scanning the QR code.
94
113
  </p>
95
114
  </div>
96
115
  </div>
@@ -1,6 +1,7 @@
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';
4
5
  // @ts-ignore - optional dependency, may not be installed in some consumers
5
6
  import { toast, ToastContainer } from 'react-toastify';
6
7
  // @ts-ignore - import styles only when package is present
@@ -21,25 +22,17 @@ function QRCodePage({ onClose, mobileBaseUrl = 'https://kyc-sdk.astraprotocol.co
21
22
  const [copied, setCopied] = useState<boolean>(false);
22
23
 
23
24
  useEffect(() => {
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);
25
+ // Store config in localStorage for mobile route to retrieve
26
+ if (sessionId && apiBaseUrl && serverKey) {
27
+ storeKycConfig(sessionId, apiBaseUrl, serverKey);
30
28
  }
31
- if (apiBaseUrl) {
32
- searchParams.set('apiBaseUrl', apiBaseUrl);
33
- }
34
- if (serverKey) {
35
- searchParams.set('serverKey', serverKey);
29
+
30
+ // Only include sessionId in URL, not apiBaseUrl or serverKey
31
+ if (sessionId) {
32
+ const mobileRoute = '/mobileroute';
33
+ const fullUrl = `${mobileBaseUrl}${mobileRoute}?sessionId=${sessionId}`;
34
+ setQrUrl(fullUrl);
36
35
  }
37
-
38
- const mobileRoute = '/mobileroute';
39
- const queryString = searchParams.toString();
40
- const fullUrl = `${mobileBaseUrl}${mobileRoute}${queryString ? `?${queryString}` : ''}`;
41
-
42
- setQrUrl(fullUrl);
43
36
  }, [mobileBaseUrl, sessionId, apiBaseUrl, serverKey]);
44
37
 
45
38
  const handleCopyUrl = async () => {
@@ -104,7 +97,7 @@ function QRCodePage({ onClose, mobileBaseUrl = 'https://kyc-sdk.astraprotocol.co
104
97
  backgroundSize: '40px 40px'
105
98
  }}></div>
106
99
 
107
- <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)] border border-white/10">
100
+ <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)]">
108
101
  {/* <button
109
102
  className="absolute top-5 right-5 bg-transparent border-none text-white cursor-pointer p-2 flex items-center justify-center rounded transition-colors hover:bg-white/10 active:bg-white/20"
110
103
  onClick={handleClose}
@@ -138,7 +131,7 @@ function QRCodePage({ onClose, mobileBaseUrl = 'https://kyc-sdk.astraprotocol.co
138
131
  <div className="w-full text-left mt-auto">
139
132
  <p className="m-0 mb-2 text-white text-xs sm:text-sm opacity-80">Or open:</p>
140
133
  <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">
141
- <code className="flex-1 text-white text-xs sm:text-sm break-all text-left m-0 font-mono line-clamp-1">{qrUrl}</code>
134
+ <code className="flex-1 text-white text-xs sm:text-sm break-all text-left m-0 font-mono line-clamp-1 ">{qrUrl}</code>
142
135
  <button
143
136
  className="bg-transparent border-none text-white cursor-pointer p-1.5 flex items-center justify-center rounded transition-colors flex-shrink-0 hover:bg-white/10 active:bg-white/20 self-end sm:self-auto"
144
137
  onClick={handleCopyUrl}
@@ -0,0 +1,125 @@
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
+