@sanctum-key/react-native-sdk 1.0.49 → 1.0.50
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/build/package.json +1 -1
- package/build/src/components/KYCElements/CountrySelection.d.ts.map +1 -1
- package/build/src/components/KYCElements/CountrySelection.js +33 -108
- package/build/src/components/KYCElements/CountrySelection.js.map +1 -1
- package/build/src/components/KYCElements/CountrySelectionTemplate.d.ts.map +1 -1
- package/build/src/components/KYCElements/CountrySelectionTemplate.js +50 -164
- package/build/src/components/KYCElements/CountrySelectionTemplate.js.map +1 -1
- package/build/src/components/KYCElements/DocumentTypeSelection.d.ts.map +1 -1
- package/build/src/components/KYCElements/DocumentTypeSelection.js +32 -109
- package/build/src/components/KYCElements/DocumentTypeSelection.js.map +1 -1
- package/build/src/components/KYCElements/IDCardCapture.d.ts.map +1 -1
- package/build/src/components/KYCElements/IDCardCapture.js +58 -25
- package/build/src/components/KYCElements/IDCardCapture.js.map +1 -1
- package/build/src/components/KYCElements/InitializationStep.d.ts.map +1 -1
- package/build/src/components/KYCElements/InitializationStep.js +13 -1
- package/build/src/components/KYCElements/InitializationStep.js.map +1 -1
- package/build/src/components/KYCElements/LocationCaptureTemplate.d.ts.map +1 -1
- package/build/src/components/KYCElements/LocationCaptureTemplate.js +46 -157
- package/build/src/components/KYCElements/LocationCaptureTemplate.js.map +1 -1
- package/build/src/components/KYCElements/SelfieCapture.d.ts.map +1 -1
- package/build/src/components/KYCElements/SelfieCapture.js +28 -24
- package/build/src/components/KYCElements/SelfieCapture.js.map +1 -1
- package/build/src/components/KYCElements/VerificationProgressTemplate.d.ts.map +1 -1
- package/build/src/components/KYCElements/VerificationProgressTemplate.js +0 -4
- package/build/src/components/KYCElements/VerificationProgressTemplate.js.map +1 -1
- package/build/src/components/SelfieCapture.d.ts.map +1 -1
- package/build/src/components/SelfieCapture.js +33 -90
- package/build/src/components/SelfieCapture.js.map +1 -1
- package/build/src/components/TemplateKYCExample.d.ts.map +1 -1
- package/build/src/components/TemplateKYCExample.js +69 -120
- package/build/src/components/TemplateKYCExample.js.map +1 -1
- package/build/src/components/TemplateKYCFlowRefactored.d.ts +0 -2
- package/build/src/components/TemplateKYCFlowRefactored.d.ts.map +1 -1
- package/build/src/components/TemplateKYCFlowRefactored.js +95 -210
- package/build/src/components/TemplateKYCFlowRefactored.js.map +1 -1
- package/build/src/hooks/useTemplateKYCFlow.d.ts.map +1 -1
- package/build/src/hooks/useTemplateKYCFlow.js.map +1 -1
- package/build/src/types/KYC.types.d.ts.map +1 -1
- package/build/src/types/KYC.types.js.map +1 -1
- package/build/src/utils/logger.d.ts +12 -4
- package/build/src/utils/logger.d.ts.map +1 -1
- package/build/src/utils/logger.js +156 -28
- package/build/src/utils/logger.js.map +1 -1
- package/package.json +1 -1
- package/src/components/KYCElements/CountrySelection.tsx +36 -109
- package/src/components/KYCElements/CountrySelectionTemplate.tsx +67 -266
- package/src/components/KYCElements/DocumentTypeSelection.tsx +34 -110
- package/src/components/KYCElements/IDCardCapture.tsx +93 -39
- package/src/components/KYCElements/InitializationStep.tsx +17 -2
- package/src/components/KYCElements/LocationCaptureTemplate.tsx +53 -170
- package/src/components/KYCElements/SelfieCapture.tsx +50 -58
- package/src/components/KYCElements/VerificationProgressTemplate.tsx +1 -4
- package/src/components/SelfieCapture.tsx +44 -100
- package/src/components/TemplateKYCExample.tsx +94 -145
- package/src/components/TemplateKYCFlowRefactored.tsx +105 -239
- package/src/hooks/useTemplateKYCFlow.tsx +1 -0
- package/src/types/KYC.types.ts +0 -1
- package/src/utils/logger.ts +182 -29
package/src/utils/logger.ts
CHANGED
|
@@ -1,48 +1,201 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*/
|
|
1
|
+
import { Platform, AppState, AppStateStatus } from 'react-native';
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
import KYCConfig from '../config/KYCConfig';
|
|
5
4
|
|
|
6
5
|
const isProduction = (): boolean => {
|
|
7
|
-
// Check for React Native __DEV__ flag
|
|
8
6
|
if (typeof __DEV__ !== 'undefined') {
|
|
9
7
|
return !__DEV__;
|
|
10
8
|
}
|
|
11
|
-
// Check for Node.js environment
|
|
12
9
|
if (typeof process !== 'undefined' && process.env) {
|
|
13
10
|
return process.env.NODE_ENV === 'production';
|
|
14
11
|
}
|
|
15
|
-
// Default to development mode if we can't determine
|
|
16
12
|
return false;
|
|
17
13
|
};
|
|
18
14
|
|
|
19
|
-
const
|
|
15
|
+
const IS_PROD = isProduction();
|
|
20
16
|
|
|
21
17
|
export const logger = {
|
|
22
|
-
log: (...args: any[]) => {
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
log: (...args: any[]) => { if (!IS_PROD) console.log(...args); },
|
|
19
|
+
error: (...args: any[]) => { if (!IS_PROD) console.error(...args); },
|
|
20
|
+
warn: (...args: any[]) => { if (!IS_PROD) console.warn(...args); },
|
|
21
|
+
info: (...args: any[]) => { if (!IS_PROD) console.info(...args); },
|
|
22
|
+
debug: (...args: any[]) => { if (!IS_PROD) console.debug(...args); },
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// ==========================================
|
|
26
|
+
// 2. SDK TELEMETRY LOGGER (REMOTE)
|
|
27
|
+
// ==========================================
|
|
28
|
+
// 🚨 FIX 1: Changed 'warn' to 'warning' to match backend enums
|
|
29
|
+
type LogLevel = 'info' | 'warning' | 'error' | 'debug';
|
|
30
|
+
|
|
31
|
+
interface LogEntry {
|
|
32
|
+
level: LogLevel;
|
|
33
|
+
message: string;
|
|
34
|
+
timestamp: string;
|
|
35
|
+
session_id?: string;
|
|
36
|
+
metadata?: any;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
class SDKTelemetryLogger {
|
|
40
|
+
private queue: LogEntry[] = [];
|
|
41
|
+
private isFlushing = false;
|
|
42
|
+
private maxQueueSize = 3;
|
|
43
|
+
private flushIntervalMs = 3000;
|
|
44
|
+
private sessionId: string | undefined;
|
|
45
|
+
private apiKey: string | undefined;
|
|
46
|
+
private timerId?: ReturnType<typeof setInterval>;
|
|
47
|
+
private appStateSubscription: any;
|
|
48
|
+
|
|
49
|
+
constructor() {
|
|
50
|
+
this.timerId = setInterval(() => this.flush(), this.flushIntervalMs);
|
|
51
|
+
|
|
52
|
+
if (Platform.OS !== 'web') {
|
|
53
|
+
this.appStateSubscription = AppState.addEventListener('change', this.handleAppStateChange);
|
|
25
54
|
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private handleAppStateChange = (nextAppState: AppStateStatus) => {
|
|
58
|
+
if (nextAppState === 'background' || nextAppState === 'inactive') {
|
|
59
|
+
this.flush();
|
|
30
60
|
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
public setSessionId(id: string) {
|
|
64
|
+
this.sessionId = id;
|
|
65
|
+
|
|
66
|
+
this.queue = this.queue.map(log => {
|
|
67
|
+
if (!log.session_id) {
|
|
68
|
+
return { ...log, session_id: id };
|
|
69
|
+
}
|
|
70
|
+
return log;
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
this.flush();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public clearSessionId() {
|
|
77
|
+
this.sessionId = undefined;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public setApiKey(key: string) {
|
|
81
|
+
this.apiKey = key;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
private parseArgs(args: any[]): { message: string, metadata: any } {
|
|
85
|
+
let message = '';
|
|
86
|
+
let metadata: any = {};
|
|
87
|
+
|
|
88
|
+
args.forEach(arg => {
|
|
89
|
+
if (typeof arg === 'string') {
|
|
90
|
+
message += (message ? ' ' : '') + arg;
|
|
91
|
+
} else if (arg instanceof Error) {
|
|
92
|
+
message += (message ? ' ' : '') + arg.message;
|
|
93
|
+
metadata.error_stack = arg.stack;
|
|
94
|
+
} else if (typeof arg === 'object' && arg !== null) {
|
|
95
|
+
Object.assign(metadata, arg);
|
|
96
|
+
} else {
|
|
97
|
+
message += (message ? ' ' : '') + String(arg);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
return { message: message || 'No message provided', metadata };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
public processLog(level: LogLevel, ...args: any[]) {
|
|
105
|
+
const { message, metadata } = this.parseArgs(args);
|
|
106
|
+
|
|
107
|
+
if (!IS_PROD) {
|
|
108
|
+
const devPrefix = `[SDK_TELEMETRY_${level.toUpperCase()}]`;
|
|
109
|
+
if (level === 'error') console.error(devPrefix, message, metadata);
|
|
110
|
+
else if (level === 'warning') console.warn(devPrefix, message, metadata); // Match updated level
|
|
111
|
+
else console.log(devPrefix, message, metadata);
|
|
35
112
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
113
|
+
|
|
114
|
+
const entry: LogEntry = {
|
|
115
|
+
level,
|
|
116
|
+
message: message.substring(0, 500),
|
|
117
|
+
timestamp: new Date().toISOString(),
|
|
118
|
+
session_id: this.sessionId,
|
|
119
|
+
metadata: {
|
|
120
|
+
...metadata,
|
|
121
|
+
os: Platform.OS,
|
|
122
|
+
osVersion: Platform.Version,
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
this.queue.push(entry);
|
|
127
|
+
|
|
128
|
+
const isError = level === 'error';
|
|
129
|
+
const hitLimit = this.queue.length >= this.maxQueueSize;
|
|
130
|
+
|
|
131
|
+
if (isError || (this.sessionId && hitLimit)) {
|
|
132
|
+
this.flush();
|
|
40
133
|
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
public async flush() {
|
|
137
|
+
if (this.queue.length === 0 || this.isFlushing) return;
|
|
138
|
+
|
|
139
|
+
const batch = this.queue.map(log => ({
|
|
140
|
+
...log,
|
|
141
|
+
session_id: log.session_id || 'pre-session-startup'
|
|
142
|
+
}));
|
|
143
|
+
|
|
144
|
+
this.isFlushing = true;
|
|
145
|
+
this.queue = [];
|
|
146
|
+
|
|
147
|
+
try {
|
|
148
|
+
const url = `${KYCConfig.getBackendUrl()}/core/sdk/logs/`;
|
|
149
|
+
|
|
150
|
+
const headers: Record<string, string> = { 'Content-Type': 'application/json' };
|
|
151
|
+
if (this.apiKey) {
|
|
152
|
+
headers['Authorization'] = `ApiKey ${this.apiKey}`;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
await axios.post(url, { logs: batch }, {
|
|
156
|
+
headers,
|
|
157
|
+
timeout: 5000
|
|
158
|
+
});
|
|
159
|
+
} catch (error: any) {
|
|
160
|
+
// 🚨 FIX 2: Stop Infinite Loops
|
|
161
|
+
// If the backend actively rejects our payload (400-499 error code), do NOT requeue it.
|
|
162
|
+
const isClientError = error.response && error.response.status >= 400 && error.response.status < 500;
|
|
163
|
+
|
|
164
|
+
if (!isClientError) {
|
|
165
|
+
// Only retry if it's a network failure or a 5xx Server Error
|
|
166
|
+
if (this.queue.length < 50) {
|
|
167
|
+
this.queue = [...batch, ...this.queue].slice(0, 50);
|
|
168
|
+
}
|
|
169
|
+
} else {
|
|
170
|
+
if (!IS_PROD) {
|
|
171
|
+
console.error("[SDK_TELEMETRY] Backend rejected log payload. Dropping batch to prevent infinite loop.", error.response.data);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
} finally {
|
|
175
|
+
this.isFlushing = false;
|
|
45
176
|
}
|
|
46
|
-
}
|
|
47
|
-
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
public destroy() {
|
|
180
|
+
if (this.timerId) clearInterval(this.timerId);
|
|
181
|
+
if (this.appStateSubscription) this.appStateSubscription.remove();
|
|
182
|
+
this.flush();
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const telemetryInstance = new SDKTelemetryLogger();
|
|
48
187
|
|
|
188
|
+
export const sdkLogger = {
|
|
189
|
+
setSessionId: (id: string) => telemetryInstance.setSessionId(id),
|
|
190
|
+
clearSessionId: () => telemetryInstance.clearSessionId(),
|
|
191
|
+
flush: () => telemetryInstance.flush(),
|
|
192
|
+
destroy: () => telemetryInstance.destroy(),
|
|
193
|
+
setApiKey: (key: string) => telemetryInstance.setApiKey(key),
|
|
194
|
+
|
|
195
|
+
log: (...args: any[]) => telemetryInstance.processLog('info', ...args),
|
|
196
|
+
info: (...args: any[]) => telemetryInstance.processLog('info', ...args),
|
|
197
|
+
// 🚨 FIX 1 (Continued): Map warn() function to send 'warning' to backend
|
|
198
|
+
warn: (...args: any[]) => telemetryInstance.processLog('warning', ...args),
|
|
199
|
+
error: (...args: any[]) => telemetryInstance.processLog('error', ...args),
|
|
200
|
+
debug: (...args: any[]) => telemetryInstance.processLog('debug', ...args),
|
|
201
|
+
};
|