@trustchex/react-native-sdk 1.250.0 → 1.266.0

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.
Files changed (100) hide show
  1. package/README.md +43 -2
  2. package/android/src/main/java/com/trustchex/reactnativesdk/DeviceBrightnessModule.kt +66 -0
  3. package/android/src/main/java/com/trustchex/reactnativesdk/TrustchexSDKPackage.kt +12 -0
  4. package/ios/DeviceBrightnessModule.h +4 -0
  5. package/ios/DeviceBrightnessModule.m +27 -0
  6. package/lib/module/Screens/Dynamic/ContractAcceptanceScreen.js +25 -0
  7. package/lib/module/Screens/Dynamic/IdentityDocumentEIDScanningScreen.js +19 -0
  8. package/lib/module/Screens/Dynamic/IdentityDocumentScanningScreen.js +19 -0
  9. package/lib/module/Screens/Dynamic/LivenessDetectionScreen.js +18 -5
  10. package/lib/module/Screens/Static/QrCodeScanningScreen.js +10 -2
  11. package/lib/module/Screens/Static/ResultScreen.js +52 -3
  12. package/lib/module/Screens/Static/VerificationSessionCheckScreen.js +82 -72
  13. package/lib/module/Shared/Components/EIDScanner.js +63 -3
  14. package/lib/module/Shared/Components/FaceCamera.js +73 -6
  15. package/lib/module/Shared/Components/IdentityDocumentCamera.js +9 -4
  16. package/lib/module/Shared/Components/LanguageSelector.js +14 -10
  17. package/lib/module/Shared/Components/NavigationManager.js +4 -2
  18. package/lib/module/Shared/Components/QrCodeScannerCamera.js +6 -1
  19. package/lib/module/Shared/Components/StyledButton.js +108 -9
  20. package/lib/module/Shared/Components/StyledTextInput.js +87 -0
  21. package/lib/module/Shared/Contexts/AppContext.js +3 -1
  22. package/lib/module/Shared/Contexts/ThemeContext.js +40 -0
  23. package/lib/module/Shared/Libs/analytics.utils.js +430 -0
  24. package/lib/module/Shared/Libs/camera.utils.js +58 -2
  25. package/lib/module/Shared/Libs/deeplink.utils.js +8 -0
  26. package/lib/module/Shared/Libs/http-client.js +89 -28
  27. package/lib/module/Shared/Services/AnalyticsService.js +404 -0
  28. package/lib/module/Shared/Types/analytics.types.js +111 -0
  29. package/lib/module/Shared/VisionCameraPlugins/BarcodeScanner/hooks/useCameraPermissions.js +1 -0
  30. package/lib/module/Translation/index.js +17 -5
  31. package/lib/module/Trustchex.js +52 -16
  32. package/lib/module/index.js +3 -0
  33. package/lib/typescript/src/Screens/Dynamic/ContractAcceptanceScreen.d.ts.map +1 -1
  34. package/lib/typescript/src/Screens/Dynamic/IdentityDocumentEIDScanningScreen.d.ts.map +1 -1
  35. package/lib/typescript/src/Screens/Dynamic/IdentityDocumentScanningScreen.d.ts.map +1 -1
  36. package/lib/typescript/src/Screens/Dynamic/LivenessDetectionScreen.d.ts.map +1 -1
  37. package/lib/typescript/src/Screens/Static/QrCodeScanningScreen.d.ts.map +1 -1
  38. package/lib/typescript/src/Screens/Static/ResultScreen.d.ts.map +1 -1
  39. package/lib/typescript/src/Screens/Static/VerificationSessionCheckScreen.d.ts.map +1 -1
  40. package/lib/typescript/src/Shared/Components/EIDScanner.d.ts.map +1 -1
  41. package/lib/typescript/src/Shared/Components/FaceCamera.d.ts +7 -1
  42. package/lib/typescript/src/Shared/Components/FaceCamera.d.ts.map +1 -1
  43. package/lib/typescript/src/Shared/Components/IdentityDocumentCamera.d.ts.map +1 -1
  44. package/lib/typescript/src/Shared/Components/LanguageSelector.d.ts.map +1 -1
  45. package/lib/typescript/src/Shared/Components/NavigationManager.d.ts.map +1 -1
  46. package/lib/typescript/src/Shared/Components/QrCodeScannerCamera.d.ts.map +1 -1
  47. package/lib/typescript/src/Shared/Components/StyledButton.d.ts +12 -2
  48. package/lib/typescript/src/Shared/Components/StyledButton.d.ts.map +1 -1
  49. package/lib/typescript/src/Shared/Components/StyledTextInput.d.ts +15 -0
  50. package/lib/typescript/src/Shared/Components/StyledTextInput.d.ts.map +1 -0
  51. package/lib/typescript/src/Shared/Contexts/AppContext.d.ts +2 -0
  52. package/lib/typescript/src/Shared/Contexts/AppContext.d.ts.map +1 -1
  53. package/lib/typescript/src/Shared/Contexts/ThemeContext.d.ts +26 -0
  54. package/lib/typescript/src/Shared/Contexts/ThemeContext.d.ts.map +1 -0
  55. package/lib/typescript/src/Shared/Libs/analytics.utils.d.ts +98 -0
  56. package/lib/typescript/src/Shared/Libs/analytics.utils.d.ts.map +1 -0
  57. package/lib/typescript/src/Shared/Libs/camera.utils.d.ts +19 -1
  58. package/lib/typescript/src/Shared/Libs/camera.utils.d.ts.map +1 -1
  59. package/lib/typescript/src/Shared/Libs/deeplink.utils.d.ts.map +1 -1
  60. package/lib/typescript/src/Shared/Libs/http-client.d.ts.map +1 -1
  61. package/lib/typescript/src/Shared/Services/AnalyticsService.d.ts +86 -0
  62. package/lib/typescript/src/Shared/Services/AnalyticsService.d.ts.map +1 -0
  63. package/lib/typescript/src/Shared/Types/analytics.types.d.ts +146 -0
  64. package/lib/typescript/src/Shared/Types/analytics.types.d.ts.map +1 -0
  65. package/lib/typescript/src/Shared/VisionCameraPlugins/BarcodeScanner/hooks/useCameraPermissions.d.ts.map +1 -1
  66. package/lib/typescript/src/Translation/Resources/tr.d.ts.map +1 -1
  67. package/lib/typescript/src/Translation/index.d.ts.map +1 -1
  68. package/lib/typescript/src/Trustchex.d.ts +1 -0
  69. package/lib/typescript/src/Trustchex.d.ts.map +1 -1
  70. package/lib/typescript/src/index.d.ts +4 -0
  71. package/lib/typescript/src/index.d.ts.map +1 -1
  72. package/package.json +6 -7
  73. package/src/Screens/Dynamic/ContractAcceptanceScreen.tsx +35 -1
  74. package/src/Screens/Dynamic/IdentityDocumentEIDScanningScreen.tsx +30 -0
  75. package/src/Screens/Dynamic/IdentityDocumentScanningScreen.tsx +30 -0
  76. package/src/Screens/Dynamic/LivenessDetectionScreen.tsx +30 -4
  77. package/src/Screens/Static/QrCodeScanningScreen.tsx +12 -2
  78. package/src/Screens/Static/ResultScreen.tsx +79 -4
  79. package/src/Screens/Static/VerificationSessionCheckScreen.tsx +113 -90
  80. package/src/Shared/Components/EIDScanner.tsx +132 -3
  81. package/src/Shared/Components/FaceCamera.tsx +81 -4
  82. package/src/Shared/Components/IdentityDocumentCamera.tsx +8 -6
  83. package/src/Shared/Components/LanguageSelector.tsx +12 -11
  84. package/src/Shared/Components/NavigationManager.tsx +5 -3
  85. package/src/Shared/Components/QrCodeScannerCamera.tsx +5 -1
  86. package/src/Shared/Components/StyledButton.tsx +141 -10
  87. package/src/Shared/Components/StyledTextInput.tsx +128 -0
  88. package/src/Shared/Contexts/AppContext.ts +4 -0
  89. package/src/Shared/Contexts/ThemeContext.tsx +67 -0
  90. package/src/Shared/Libs/analytics.utils.ts +644 -0
  91. package/src/Shared/Libs/camera.utils.ts +74 -2
  92. package/src/Shared/Libs/deeplink.utils.ts +5 -0
  93. package/src/Shared/Libs/http-client.ts +105 -31
  94. package/src/Shared/Services/AnalyticsService.ts +470 -0
  95. package/src/Shared/Types/analytics.types.ts +179 -0
  96. package/src/Shared/VisionCameraPlugins/BarcodeScanner/hooks/useCameraPermissions.ts +1 -0
  97. package/src/Translation/Resources/tr.ts +2 -1
  98. package/src/Translation/index.ts +21 -10
  99. package/src/Trustchex.tsx +65 -20
  100. package/src/index.tsx +33 -0
package/src/Trustchex.tsx CHANGED
@@ -2,8 +2,8 @@ import React, { useEffect, useState, useMemo } from 'react';
2
2
  import { NavigationContainer } from '@react-navigation/native';
3
3
  import { createNativeStackNavigator } from '@react-navigation/native-stack';
4
4
  import { View, ActivityIndicator, StyleSheet } from 'react-native';
5
- import { MD3LightTheme, PaperProvider } from 'react-native-paper';
6
5
  import 'react-native-get-random-values';
6
+ import { ThemeProvider } from './Shared/Contexts/ThemeContext';
7
7
 
8
8
  import IdentityDocumentEIDScanningScreen from './Screens/Dynamic/IdentityDocumentEIDScanningScreen';
9
9
  import IdentityDocumentScanningScreen from './Screens/Dynamic/IdentityDocumentScanningScreen';
@@ -15,6 +15,11 @@ import QrCodeScanningScreen from './Screens/Static/QrCodeScanningScreen';
15
15
  import AppContext from './Shared/Contexts/AppContext';
16
16
  import i18n from './Translation';
17
17
  import { initializeTTS } from './Shared/Libs/tts.utils';
18
+ import { analyticsService } from './Shared/Services/AnalyticsService';
19
+ import {
20
+ AnalyticsEventCategory,
21
+ AnalyticsEventName,
22
+ } from './Shared/Types/analytics.types';
18
23
 
19
24
  const Stack = createNativeStackNavigator();
20
25
 
@@ -32,6 +37,7 @@ interface TrustchexProps {
32
37
  locale?: 'en' | 'tr';
33
38
  onCompleted?: () => void;
34
39
  onError?: (error: string) => void;
40
+ enableAnalytics?: boolean;
35
41
  }
36
42
 
37
43
  const DEFAULT_BRANDING: TrustchexBranding = {
@@ -48,11 +54,19 @@ const Trustchex: React.FC<TrustchexProps> = ({
48
54
  locale: propLocale,
49
55
  onCompleted,
50
56
  onError,
57
+ enableAnalytics = true,
51
58
  }) => {
59
+ useEffect(() => {
60
+ console.log('[Trustchex] Props updated:', { baseUrl: propBaseUrl, sessionId: propSessionId, enableAnalytics });
61
+ }, [propBaseUrl, propSessionId, enableAnalytics]);
62
+
52
63
  const [baseUrl, setBaseUrl] = useState<string | null>(null);
53
64
  const [sessionId, setSessionId] = useState<string | null>(null);
54
- const [locale, setLocale] = useState(propLocale || i18n.language);
65
+ const [locale, setLocale] = useState(
66
+ propLocale || (i18n.language as 'en' | 'tr')
67
+ );
55
68
  const [isInitialized, setIsInitialized] = useState(false);
69
+ const [analyticsInitialized, setAnalyticsInitialized] = useState(false);
56
70
 
57
71
  const branding = useMemo(
58
72
  () => ({
@@ -62,40 +76,66 @@ const Trustchex: React.FC<TrustchexProps> = ({
62
76
  [propBranding]
63
77
  );
64
78
 
65
- const theme = useMemo(
66
- () => ({
67
- ...MD3LightTheme,
68
- colors: {
69
- ...MD3LightTheme.colors,
70
- primary: branding.primaryColor,
71
- secondary: branding.secondaryColor,
72
- tertiary: branding.tertiaryColor,
73
- },
74
- }),
75
- [branding]
76
- );
77
-
78
79
  const contextValue = useMemo(
79
80
  () => ({
80
81
  isDemoSession: false,
81
- baseUrl,
82
+ baseUrl: baseUrl || '',
82
83
  locale,
83
84
  branding,
84
85
  identificationInfo: {
85
- sessionId,
86
+ sessionId: sessionId || '',
86
87
  identificationId: '',
87
88
  consent: {
88
89
  contractIds: [],
89
90
  deviceInfo: '',
90
91
  },
91
- locale: propLocale || i18n.language,
92
+ locale: propLocale || (i18n.language as 'en' | 'tr'),
92
93
  },
93
94
  onCompleted,
94
95
  onError,
96
+ setSessionId,
97
+ setBaseUrl,
95
98
  }),
96
99
  [baseUrl, locale, branding, sessionId, propLocale, onCompleted, onError]
97
100
  );
98
101
 
102
+ // Initialize analytics IMMEDIATELY when SDK mounts or session ID changes
103
+ useEffect(() => {
104
+ console.log('[Trustchex] Analytics check:', {
105
+ enableAnalytics,
106
+ hasBaseUrl: !!baseUrl,
107
+ hasSessionId: !!sessionId,
108
+ analyticsInitialized,
109
+ sessionId: sessionId?.substring(0, 8) + '...'
110
+ });
111
+
112
+ if (enableAnalytics && baseUrl && sessionId && !analyticsInitialized) {
113
+ console.log('[Trustchex] Initializing analytics...');
114
+ // Initialize analytics synchronously with the verification sessionId
115
+ analyticsService
116
+ .initialize({
117
+ enabled: true,
118
+ baseUrl: baseUrl,
119
+ verificationSessionId: sessionId, // Pass the verification session ID from backend
120
+ })
121
+ .then(() => {
122
+ console.log('[Trustchex] Analytics initialized successfully');
123
+ setAnalyticsInitialized(true);
124
+ // Track session start as the very first event
125
+ analyticsService.trackEvent(
126
+ AnalyticsEventName.SESSION_START,
127
+ AnalyticsEventCategory.SESSION,
128
+ {
129
+ source: 'sdk_init',
130
+ }
131
+ );
132
+ })
133
+ .catch((error) => {
134
+ console.warn('[Trustchex] Failed to initialize analytics:', error);
135
+ });
136
+ }
137
+ }, [enableAnalytics, baseUrl, sessionId, analyticsInitialized]);
138
+
99
139
  useEffect(() => {
100
140
  initializeTTS();
101
141
  }, []);
@@ -119,6 +159,7 @@ const Trustchex: React.FC<TrustchexProps> = ({
119
159
  if (propLocale) {
120
160
  setLocale(propLocale);
121
161
  i18n.changeLanguage(propLocale);
162
+ analyticsService.setLocale(propLocale);
122
163
  }
123
164
  }, [propLocale]);
124
165
 
@@ -131,7 +172,11 @@ const Trustchex: React.FC<TrustchexProps> = ({
131
172
  }
132
173
 
133
174
  return (
134
- <PaperProvider theme={theme}>
175
+ <ThemeProvider
176
+ primaryColor={branding.primaryColor}
177
+ secondaryColor={branding.secondaryColor}
178
+ tertiaryColor={branding.tertiaryColor}
179
+ >
135
180
  <AppContext.Provider value={contextValue}>
136
181
  <NavigationContainer>
137
182
  <Stack.Navigator
@@ -170,7 +215,7 @@ const Trustchex: React.FC<TrustchexProps> = ({
170
215
  </Stack.Navigator>
171
216
  </NavigationContainer>
172
217
  </AppContext.Provider>
173
- </PaperProvider>
218
+ </ThemeProvider>
174
219
  );
175
220
  };
176
221
 
package/src/index.tsx CHANGED
@@ -1,5 +1,38 @@
1
1
  import Trustchex from './Trustchex';
2
2
 
3
3
  export { handleDeepLink } from './Shared/Libs/deeplink.utils';
4
+ export { analyticsService } from './Shared/Services/AnalyticsService';
5
+ export {
6
+ trackScreenView,
7
+ trackScreenExit,
8
+ trackButtonClick,
9
+ trackError,
10
+ trackErrorWithDetails,
11
+ trackApiCall,
12
+ trackVerificationStart,
13
+ trackVerificationComplete,
14
+ trackConsentGiven,
15
+ trackSessionStart,
16
+ trackSessionEnd,
17
+ trackNFCScanStart,
18
+ trackNFCScanComplete,
19
+ trackNFCScanFailed,
20
+ trackFunnelStep,
21
+ trackStepAbandoned,
22
+ trackStepSkipped,
23
+ useScreenTracking,
24
+ } from './Shared/Libs/analytics.utils';
25
+ export {
26
+ AnalyticsEventCategory,
27
+ AnalyticsEventName,
28
+ ErrorCategory,
29
+ } from './Shared/Types/analytics.types';
30
+ export type {
31
+ AnalyticsConfig,
32
+ AnalyticsEvent,
33
+ ErrorSeverity,
34
+ ErrorContext,
35
+ ErrorEventMetadata,
36
+ } from './Shared/Types/analytics.types';
4
37
 
5
38
  export default Trustchex;