@robylon/react-native-sdk 2.0.16-staging.2 → 2.0.16-staging.3
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/.npmignore.development +18 -0
- package/babel.config.js +15 -15
- package/ios/Podfile +12 -0
- package/lib/commonjs/Chatbotsdk.js +1 -1
- package/lib/commonjs/Chatbotsdk.js.map +1 -1
- package/lib/commonjs/FloatingButton.js +1 -1
- package/lib/commonjs/FloatingButton.js.map +1 -1
- package/lib/commonjs/components/DebugButton.js +2 -0
- package/lib/commonjs/components/DebugButton.js.map +1 -0
- package/lib/commonjs/components/ErrorBoundary.js +2 -0
- package/lib/commonjs/components/ErrorBoundary.js.map +1 -0
- package/lib/commonjs/constants/errorConstants.js +2 -0
- package/lib/commonjs/constants/errorConstants.js.map +1 -0
- package/lib/commonjs/constants.js +1 -1
- package/lib/commonjs/constants.js.map +1 -1
- package/lib/commonjs/hooks/useChatbotEvents.js +2 -0
- package/lib/commonjs/hooks/useChatbotEvents.js.map +1 -0
- package/lib/commonjs/index.js +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/services/ErrorTrackingService.js +2 -0
- package/lib/commonjs/services/ErrorTrackingService.js.map +1 -0
- package/lib/commonjs/types/events.js +2 -0
- package/lib/commonjs/types/events.js.map +1 -0
- package/lib/commonjs/types/react-native-flipper-performance-plugin.d.js +2 -0
- package/lib/commonjs/types/react-native-flipper-performance-plugin.d.js.map +1 -0
- package/lib/commonjs/types/react-native-globals.d.js +2 -0
- package/lib/commonjs/types/react-native-globals.d.js.map +1 -0
- package/lib/commonjs/utils/cookieUtils.js +2 -0
- package/lib/commonjs/utils/cookieUtils.js.map +1 -0
- package/lib/commonjs/utils/debugConfig.js +2 -0
- package/lib/commonjs/utils/debugConfig.js.map +1 -0
- package/lib/commonjs/utils/debugMenu.js +2 -0
- package/lib/commonjs/utils/debugMenu.js.map +1 -0
- package/lib/commonjs/utils/errorHandler.js +2 -0
- package/lib/commonjs/utils/errorHandler.js.map +1 -0
- package/lib/commonjs/utils/logger.js +2 -0
- package/lib/commonjs/utils/logger.js.map +1 -0
- package/lib/commonjs/utils/systemInfo.js +2 -0
- package/lib/commonjs/utils/systemInfo.js.map +1 -0
- package/lib/commonjs/utils/webViewStorage.js +2 -0
- package/lib/commonjs/utils/webViewStorage.js.map +1 -0
- package/lib/commonjs/version.js +2 -0
- package/lib/commonjs/version.js.map +1 -0
- package/lib/module/Chatbotsdk.js +1 -1
- package/lib/module/Chatbotsdk.js.map +1 -1
- package/lib/module/FloatingButton.js +1 -1
- package/lib/module/FloatingButton.js.map +1 -1
- package/lib/module/components/DebugButton.js +2 -0
- package/lib/module/components/DebugButton.js.map +1 -0
- package/lib/module/components/ErrorBoundary.js +2 -0
- package/lib/module/components/ErrorBoundary.js.map +1 -0
- package/lib/module/constants/errorConstants.js +2 -0
- package/lib/module/constants/errorConstants.js.map +1 -0
- package/lib/module/constants.js +1 -1
- package/lib/module/constants.js.map +1 -1
- package/lib/module/hooks/useChatbotEvents.js +2 -0
- package/lib/module/hooks/useChatbotEvents.js.map +1 -0
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/services/ErrorTrackingService.js +2 -0
- package/lib/module/services/ErrorTrackingService.js.map +1 -0
- package/lib/module/types/events.js +2 -0
- package/lib/module/types/events.js.map +1 -0
- package/lib/module/types/react-native-flipper-performance-plugin.d.js +2 -0
- package/lib/module/types/react-native-flipper-performance-plugin.d.js.map +1 -0
- package/lib/module/types/react-native-globals.d.js +2 -0
- package/lib/module/types/react-native-globals.d.js.map +1 -0
- package/lib/module/utils/cookieUtils.js +2 -0
- package/lib/module/utils/cookieUtils.js.map +1 -0
- package/lib/module/utils/debugConfig.js +2 -0
- package/lib/module/utils/debugConfig.js.map +1 -0
- package/lib/module/utils/debugMenu.js +2 -0
- package/lib/module/utils/debugMenu.js.map +1 -0
- package/lib/module/utils/errorHandler.js +2 -0
- package/lib/module/utils/errorHandler.js.map +1 -0
- package/lib/module/utils/logger.js +2 -0
- package/lib/module/utils/logger.js.map +1 -0
- package/lib/module/utils/systemInfo.js +2 -0
- package/lib/module/utils/systemInfo.js.map +1 -0
- package/lib/module/utils/webViewStorage.js +2 -0
- package/lib/module/utils/webViewStorage.js.map +1 -0
- package/lib/module/version.js +2 -0
- package/lib/module/version.js.map +1 -0
- package/lib/typescript/Chatbotsdk.d.ts +9 -10
- package/lib/typescript/Chatbotsdk.d.ts.map +1 -1
- package/lib/typescript/FloatingButton.d.ts.map +1 -1
- package/lib/typescript/components/DebugButton.d.ts +4 -0
- package/lib/typescript/components/DebugButton.d.ts.map +1 -0
- package/lib/typescript/components/ErrorBoundary.d.ts +16 -0
- package/lib/typescript/components/ErrorBoundary.d.ts.map +1 -0
- package/lib/typescript/constants/errorConstants.d.ts +18 -0
- package/lib/typescript/constants/errorConstants.d.ts.map +1 -0
- package/lib/typescript/hooks/useChatbotEvents.d.ts +17 -0
- package/lib/typescript/hooks/useChatbotEvents.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +5 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/services/ErrorTrackingService.d.ts +34 -0
- package/lib/typescript/services/ErrorTrackingService.d.ts.map +1 -0
- package/lib/typescript/types/events.d.ts +22 -0
- package/lib/typescript/types/events.d.ts.map +1 -0
- package/lib/typescript/utils/cookieUtils.d.ts +2 -0
- package/lib/typescript/utils/cookieUtils.d.ts.map +1 -0
- package/lib/typescript/utils/debugConfig.d.ts +8 -0
- package/lib/typescript/utils/debugConfig.d.ts.map +1 -0
- package/lib/typescript/utils/debugMenu.d.ts +3 -0
- package/lib/typescript/utils/debugMenu.d.ts.map +1 -0
- package/lib/typescript/utils/errorHandler.d.ts +2 -0
- package/lib/typescript/utils/errorHandler.d.ts.map +1 -0
- package/lib/typescript/utils/logger.d.ts +7 -0
- package/lib/typescript/utils/logger.d.ts.map +1 -0
- package/lib/typescript/utils/systemInfo.d.ts +19 -0
- package/lib/typescript/utils/systemInfo.d.ts.map +1 -0
- package/lib/typescript/utils/webViewStorage.d.ts +16 -0
- package/lib/typescript/utils/webViewStorage.d.ts.map +1 -0
- package/lib/typescript/version.d.ts +2 -0
- package/lib/typescript/version.d.ts.map +1 -0
- package/package.json +8 -2
- package/scripts/generate-version.js +9 -0
- package/src/Chatbotsdk.tsx +426 -151
- package/src/FloatingButton.tsx +18 -1
- package/src/components/DebugButton.tsx +46 -0
- package/src/components/ErrorBoundary.tsx +38 -0
- package/src/constants/errorConstants.ts +21 -0
- package/src/hooks/useChatbotEvents.ts +93 -0
- package/src/index.tsx +9 -1
- package/src/services/ErrorTrackingService.ts +217 -0
- package/src/types/events.ts +25 -0
- package/src/types/react-native-flipper-performance-plugin.d.ts +3 -0
- package/src/types/react-native-globals.d.ts +10 -0
- package/src/utils/cookieUtils.ts +7 -0
- package/src/utils/debugConfig.ts +56 -0
- package/src/utils/debugMenu.ts +14 -0
- package/src/utils/errorHandler.ts +58 -0
- package/src/utils/logger.ts +14 -0
- package/src/utils/systemInfo.ts +84 -0
- package/src/utils/webViewStorage.ts +62 -0
- package/src/version.ts +2 -0
package/src/FloatingButton.tsx
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { TouchableOpacity, StyleSheet, Text, Image } from "react-native";
|
|
3
|
+
import { errorTracker } from "./services/ErrorTrackingService";
|
|
4
|
+
import { ErrorTypes } from "./constants/errorConstants";
|
|
3
5
|
|
|
4
6
|
interface FloatingButtonProps {
|
|
5
7
|
onPress: () => void;
|
|
@@ -12,13 +14,28 @@ const FloatingButton: React.FC<FloatingButtonProps> = ({
|
|
|
12
14
|
brandColor = "#007AFF", // Default color
|
|
13
15
|
imageUrl,
|
|
14
16
|
}) => {
|
|
17
|
+
const handleImageError = () => {
|
|
18
|
+
errorTracker.trackError(
|
|
19
|
+
new Error("Failed to load button image"),
|
|
20
|
+
"FloatingButton",
|
|
21
|
+
{
|
|
22
|
+
type: ErrorTypes.RUNTIME_ERROR,
|
|
23
|
+
context: { imageUrl },
|
|
24
|
+
}
|
|
25
|
+
);
|
|
26
|
+
};
|
|
27
|
+
|
|
15
28
|
return (
|
|
16
29
|
<TouchableOpacity
|
|
17
30
|
style={[styles.button, { backgroundColor: brandColor }]}
|
|
18
31
|
onPress={onPress}
|
|
19
32
|
>
|
|
20
33
|
{imageUrl ? (
|
|
21
|
-
<Image
|
|
34
|
+
<Image
|
|
35
|
+
source={{ uri: imageUrl }}
|
|
36
|
+
style={styles.buttonImage}
|
|
37
|
+
onError={handleImageError}
|
|
38
|
+
/>
|
|
22
39
|
) : (
|
|
23
40
|
<Text style={styles.buttonText}>Chat</Text>
|
|
24
41
|
)}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { TouchableOpacity, Text, StyleSheet, View } from "react-native";
|
|
3
|
+
import { openDebugMenu } from "../utils/debugMenu";
|
|
4
|
+
import { openDebuggerFromApp } from "../utils/debugMenu";
|
|
5
|
+
|
|
6
|
+
const DebugButton = () => {
|
|
7
|
+
if (!__DEV__) return null;
|
|
8
|
+
|
|
9
|
+
return (
|
|
10
|
+
<View style={styles.debugContainer}>
|
|
11
|
+
<TouchableOpacity style={styles.debugButton} onPress={openDebugMenu}>
|
|
12
|
+
<Text style={styles.debugText}>Menu</Text>
|
|
13
|
+
</TouchableOpacity>
|
|
14
|
+
<TouchableOpacity
|
|
15
|
+
style={[styles.debugButton, styles.debuggerButton]}
|
|
16
|
+
onPress={openDebuggerFromApp}
|
|
17
|
+
>
|
|
18
|
+
<Text style={styles.debugText}>Debug</Text>
|
|
19
|
+
</TouchableOpacity>
|
|
20
|
+
</View>
|
|
21
|
+
);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const styles = StyleSheet.create({
|
|
25
|
+
debugContainer: {
|
|
26
|
+
position: "absolute",
|
|
27
|
+
top: 40,
|
|
28
|
+
right: 10,
|
|
29
|
+
flexDirection: "row",
|
|
30
|
+
gap: 8,
|
|
31
|
+
},
|
|
32
|
+
debugButton: {
|
|
33
|
+
backgroundColor: "rgba(0,0,0,0.7)",
|
|
34
|
+
padding: 8,
|
|
35
|
+
borderRadius: 4,
|
|
36
|
+
},
|
|
37
|
+
debuggerButton: {
|
|
38
|
+
backgroundColor: "rgba(255,0,0,0.7)",
|
|
39
|
+
},
|
|
40
|
+
debugText: {
|
|
41
|
+
color: "white",
|
|
42
|
+
fontSize: 12,
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
export default DebugButton;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React, { Component, ErrorInfo, ReactNode } from "react";
|
|
2
|
+
import { errorTracker } from "../services/ErrorTrackingService";
|
|
3
|
+
import { ErrorTypes } from "../constants/errorConstants";
|
|
4
|
+
|
|
5
|
+
interface Props {
|
|
6
|
+
children: ReactNode;
|
|
7
|
+
componentName: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface State {
|
|
11
|
+
hasError: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export class ErrorBoundary extends Component<Props, State> {
|
|
15
|
+
constructor(props: Props) {
|
|
16
|
+
super(props);
|
|
17
|
+
this.state = { hasError: false };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
static getDerivedStateFromError(_: Error): State {
|
|
21
|
+
return { hasError: true };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
componentDidCatch(error: Error, errorInfo: ErrorInfo) {
|
|
25
|
+
errorTracker.trackError(error, this.props.componentName, {
|
|
26
|
+
errorInfo,
|
|
27
|
+
type: ErrorTypes.RUNTIME_ERROR,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
render() {
|
|
32
|
+
if (this.state.hasError) {
|
|
33
|
+
return null; // Or a fallback UI if needed
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return this.props.children;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export enum ErrorCodes {
|
|
2
|
+
MISSING_API_KEY = "MISSING_API_KEY",
|
|
3
|
+
ERROR_TRACKING_INIT_FAILED = "ERROR_TRACKING_INIT_FAILED",
|
|
4
|
+
WEBVIEW_LOAD_ERROR = "WEBVIEW_LOAD_ERROR",
|
|
5
|
+
CONFIG_FETCH_ERROR = "CONFIG_FETCH_ERROR",
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export enum ErrorTypes {
|
|
9
|
+
INITIALIZATION_ERROR = "INITIALIZATION_ERROR",
|
|
10
|
+
RUNTIME_ERROR = "RUNTIME_ERROR",
|
|
11
|
+
NETWORK_ERROR = "NETWORK_ERROR",
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const ErrorMessages = {
|
|
15
|
+
[ErrorCodes.MISSING_API_KEY]: (apiKey: any) =>
|
|
16
|
+
`Invalid API key: ${apiKey}. Please provide a valid API key.`,
|
|
17
|
+
[ErrorCodes.ERROR_TRACKING_INIT_FAILED]:
|
|
18
|
+
"Failed to initialize error tracking service.",
|
|
19
|
+
[ErrorCodes.WEBVIEW_LOAD_ERROR]: "Failed to load chatbot interface.",
|
|
20
|
+
[ErrorCodes.CONFIG_FETCH_ERROR]: "Failed to fetch chatbot configuration.",
|
|
21
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
import { getSystemInfo } from "../utils/systemInfo";
|
|
3
|
+
import { logger } from "../utils/logger";
|
|
4
|
+
import {
|
|
5
|
+
ChatbotEventType,
|
|
6
|
+
AllEventTypes,
|
|
7
|
+
ChatbotEventHandler,
|
|
8
|
+
} from "../types/events";
|
|
9
|
+
import { API_URL } from "../constants";
|
|
10
|
+
|
|
11
|
+
interface EventHookProps {
|
|
12
|
+
api_key: string;
|
|
13
|
+
chatbotConfig: any;
|
|
14
|
+
user_profile?: Record<string, any>;
|
|
15
|
+
onEvent?: ChatbotEventHandler;
|
|
16
|
+
systemInfo: { os: string; browser: string }; // Add this to get system info from WebView
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const useChatbotEvents = ({
|
|
20
|
+
api_key,
|
|
21
|
+
chatbotConfig,
|
|
22
|
+
user_profile,
|
|
23
|
+
onEvent,
|
|
24
|
+
systemInfo,
|
|
25
|
+
}: EventHookProps) => {
|
|
26
|
+
const onInternalEvent = useCallback(
|
|
27
|
+
async (
|
|
28
|
+
eventType: AllEventTypes,
|
|
29
|
+
additionalData: Record<string, any> = {}
|
|
30
|
+
) => {
|
|
31
|
+
if (!api_key) return;
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
const apiUrl = API_URL;
|
|
35
|
+
const sysInfo = getSystemInfo(systemInfo);
|
|
36
|
+
|
|
37
|
+
const eventData = {
|
|
38
|
+
trigger_time: Date.now(),
|
|
39
|
+
channel: "CHATBOT",
|
|
40
|
+
org_id: api_key,
|
|
41
|
+
client_user_id: chatbotConfig?.isAnonymous
|
|
42
|
+
? "Anonymous"
|
|
43
|
+
: String(chatbotConfig?.userId || ""),
|
|
44
|
+
event_type: eventType,
|
|
45
|
+
user_profile: { ...(user_profile || {}) },
|
|
46
|
+
...additionalData,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const payload = {
|
|
50
|
+
org_id: api_key,
|
|
51
|
+
event_data: eventData,
|
|
52
|
+
metadata: {
|
|
53
|
+
timestamp: Date.now(),
|
|
54
|
+
...sysInfo,
|
|
55
|
+
},
|
|
56
|
+
event_type: "INFO",
|
|
57
|
+
user_id: chatbotConfig?.userId,
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
logger.debug("Sending internal event:", payload);
|
|
61
|
+
|
|
62
|
+
const response = await fetch(`${apiUrl}/users/sdk/record-logs/`, {
|
|
63
|
+
method: "POST",
|
|
64
|
+
headers: { "Content-Type": "application/json" },
|
|
65
|
+
body: JSON.stringify(payload),
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
if (!response.ok) {
|
|
69
|
+
throw new Error(
|
|
70
|
+
`Failed to send internal event: ${response.statusText}`
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
} catch (error) {
|
|
74
|
+
logger.error("Failed to send internal event:", error);
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
[api_key, chatbotConfig, user_profile, systemInfo]
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
const emitEvent = useCallback(
|
|
81
|
+
(type: ChatbotEventType, data?: any) => {
|
|
82
|
+
const timestamp = Date.now();
|
|
83
|
+
onEvent?.({ type, timestamp, data });
|
|
84
|
+
onInternalEvent(type, { ...data, timestamp });
|
|
85
|
+
},
|
|
86
|
+
[onEvent, onInternalEvent]
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
return {
|
|
90
|
+
emitEvent,
|
|
91
|
+
onInternalEvent,
|
|
92
|
+
};
|
|
93
|
+
};
|
package/src/index.tsx
CHANGED
|
@@ -1,2 +1,10 @@
|
|
|
1
|
-
export { default as
|
|
1
|
+
export { default as Chatbot } from "./Chatbotsdk";
|
|
2
2
|
export { openChatbot } from "./openChatbot";
|
|
3
|
+
export {
|
|
4
|
+
errorTracker,
|
|
5
|
+
ErrorTrackingService,
|
|
6
|
+
} from "./services/ErrorTrackingService";
|
|
7
|
+
export * from "./constants/errorConstants";
|
|
8
|
+
export * from "./types/events";
|
|
9
|
+
|
|
10
|
+
export type { ChatbotProps } from "./Chatbotsdk";
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { getSystemInfo } from "../utils/systemInfo";
|
|
2
|
+
import { logger } from "../utils/logger";
|
|
3
|
+
import { API_URL } from "../constants";
|
|
4
|
+
import { Platform } from "react-native";
|
|
5
|
+
|
|
6
|
+
export enum EventType {
|
|
7
|
+
ERROR = "ERROR",
|
|
8
|
+
INFO = "INFO",
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface ErrorEvent {
|
|
12
|
+
message: string;
|
|
13
|
+
stack?: string;
|
|
14
|
+
componentName?: string | null | undefined;
|
|
15
|
+
additionalInfo?: Record<string, any>;
|
|
16
|
+
timestamp: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface LogPayload {
|
|
20
|
+
org_id: string;
|
|
21
|
+
event_data: ErrorEvent;
|
|
22
|
+
metadata: Record<string, any>;
|
|
23
|
+
event_type: EventType;
|
|
24
|
+
user_id?: string | number | null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export class ErrorTrackingService {
|
|
28
|
+
private static instance: ErrorTrackingService;
|
|
29
|
+
private apiKey: string = "";
|
|
30
|
+
private userId: string | number | null | undefined = null;
|
|
31
|
+
private preInitQueue: Array<{
|
|
32
|
+
error: Error | string;
|
|
33
|
+
componentName?: string | null | undefined;
|
|
34
|
+
additionalInfo?: Record<string, any>;
|
|
35
|
+
}> = [];
|
|
36
|
+
private isInitialized = false;
|
|
37
|
+
|
|
38
|
+
private constructor() {}
|
|
39
|
+
|
|
40
|
+
static getInstance(): ErrorTrackingService {
|
|
41
|
+
if (!ErrorTrackingService.instance) {
|
|
42
|
+
ErrorTrackingService.instance = new ErrorTrackingService();
|
|
43
|
+
}
|
|
44
|
+
return ErrorTrackingService.instance;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
initialize(apiKey: string, userId: string | number | null = null) {
|
|
48
|
+
try {
|
|
49
|
+
// Handle pre-init errors
|
|
50
|
+
if (this.preInitQueue.length > 0) {
|
|
51
|
+
const payload: LogPayload = {
|
|
52
|
+
org_id: "UNINITALIZED",
|
|
53
|
+
event_data: {
|
|
54
|
+
message: `SDK Initialization Failed: Required parameter 'api_key' is ${
|
|
55
|
+
apiKey === undefined
|
|
56
|
+
? "undefined"
|
|
57
|
+
: apiKey === null
|
|
58
|
+
? "null"
|
|
59
|
+
: apiKey === ""
|
|
60
|
+
? "empty string"
|
|
61
|
+
: `invalid: ${apiKey}`
|
|
62
|
+
}`,
|
|
63
|
+
componentName: "ErrorTrackingService",
|
|
64
|
+
additionalInfo: {
|
|
65
|
+
preInitError: true,
|
|
66
|
+
apiKey,
|
|
67
|
+
userId,
|
|
68
|
+
timestamp: Date.now(),
|
|
69
|
+
},
|
|
70
|
+
timestamp: Date.now(),
|
|
71
|
+
},
|
|
72
|
+
metadata: getSystemInfo({ os: Platform.OS, browser: "React Native" }),
|
|
73
|
+
event_type: EventType.ERROR,
|
|
74
|
+
user_id: userId,
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
this.sendLog(payload).catch((error) =>
|
|
78
|
+
logger.error("Send log error:", error)
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
this.apiKey = apiKey;
|
|
83
|
+
this.userId = userId;
|
|
84
|
+
this.isInitialized = true;
|
|
85
|
+
|
|
86
|
+
this.processPreInitQueue();
|
|
87
|
+
} catch (error) {
|
|
88
|
+
logger.error("Error during ErrorTrackingService initialization:", error);
|
|
89
|
+
this.preInitQueue.push({
|
|
90
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
91
|
+
componentName: "ErrorTrackingService",
|
|
92
|
+
additionalInfo: { apiKey, userId },
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
private async processPreInitQueue() {
|
|
98
|
+
if (!this.preInitQueue.length) return;
|
|
99
|
+
|
|
100
|
+
logger.info(
|
|
101
|
+
`Processing ${this.preInitQueue.length} pre-initialization errors`
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
for (const item of this.preInitQueue) {
|
|
105
|
+
await this.trackError(item.error, item.componentName, {
|
|
106
|
+
...item.additionalInfo,
|
|
107
|
+
preInitError: true,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
this.preInitQueue = [];
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
private async sendLog(payload: LogPayload): Promise<void> {
|
|
115
|
+
try {
|
|
116
|
+
logger.debug("Sending error log:", payload);
|
|
117
|
+
const response = await fetch(`${API_URL}/users/sdk/record-logs/`, {
|
|
118
|
+
method: "POST",
|
|
119
|
+
headers: {
|
|
120
|
+
"Content-Type": "application/json",
|
|
121
|
+
},
|
|
122
|
+
body: JSON.stringify(payload),
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
if (!response.ok) {
|
|
126
|
+
logger.error("Failed to send error log:", await response.text());
|
|
127
|
+
}
|
|
128
|
+
} catch (error) {
|
|
129
|
+
logger.error("Error sending log:", error);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async trackError(
|
|
134
|
+
error: Error | string,
|
|
135
|
+
componentName: string | null | undefined,
|
|
136
|
+
additionalInfo?: Record<string, any>
|
|
137
|
+
) {
|
|
138
|
+
if (!this.isInitialized) {
|
|
139
|
+
const payload: LogPayload = {
|
|
140
|
+
org_id: "UNINITALIZED",
|
|
141
|
+
event_data: {
|
|
142
|
+
message: error instanceof Error ? error.message : error,
|
|
143
|
+
stack: error instanceof Error ? error.stack : undefined,
|
|
144
|
+
componentName,
|
|
145
|
+
additionalInfo: {
|
|
146
|
+
...additionalInfo,
|
|
147
|
+
preInitError: true,
|
|
148
|
+
timestamp: Date.now(),
|
|
149
|
+
},
|
|
150
|
+
timestamp: Date.now(),
|
|
151
|
+
},
|
|
152
|
+
metadata: getSystemInfo({ os: Platform.OS, browser: "React Native" }),
|
|
153
|
+
event_type: EventType.ERROR,
|
|
154
|
+
user_id: this.userId,
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
try {
|
|
158
|
+
await this.sendLog(payload);
|
|
159
|
+
} catch (sendError) {
|
|
160
|
+
this.preInitQueue.push({ error, componentName, additionalInfo });
|
|
161
|
+
logger.warn("Error tracked before initialization, queuing:", error);
|
|
162
|
+
}
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const errorEvent: ErrorEvent = {
|
|
167
|
+
message: error instanceof Error ? error.message : error,
|
|
168
|
+
stack: error instanceof Error ? error.stack : undefined,
|
|
169
|
+
componentName,
|
|
170
|
+
additionalInfo: {
|
|
171
|
+
...additionalInfo,
|
|
172
|
+
timestamp: Date.now(),
|
|
173
|
+
},
|
|
174
|
+
timestamp: Date.now(),
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
const payload: LogPayload = {
|
|
178
|
+
org_id: this.apiKey || "UNINITALIZED",
|
|
179
|
+
event_data: errorEvent,
|
|
180
|
+
metadata: getSystemInfo({ os: Platform.OS, browser: "React Native" }),
|
|
181
|
+
event_type: EventType.ERROR,
|
|
182
|
+
user_id: this.userId,
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
await this.sendLog(payload);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
async trackInfo(
|
|
189
|
+
message: string,
|
|
190
|
+
componentName: string | null | undefined,
|
|
191
|
+
additionalInfo?: Record<string, any>
|
|
192
|
+
) {
|
|
193
|
+
if (!this.apiKey) {
|
|
194
|
+
logger.error("Error tracking not initialized");
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const infoEvent: ErrorEvent = {
|
|
199
|
+
message,
|
|
200
|
+
componentName,
|
|
201
|
+
additionalInfo,
|
|
202
|
+
timestamp: Date.now(),
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
const payload: LogPayload = {
|
|
206
|
+
org_id: this.apiKey,
|
|
207
|
+
event_data: infoEvent,
|
|
208
|
+
metadata: getSystemInfo({ os: Platform.OS, browser: "React Native" }),
|
|
209
|
+
event_type: EventType.INFO,
|
|
210
|
+
user_id: this.userId,
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
await this.sendLog(payload);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export const errorTracker = ErrorTrackingService.getInstance();
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export enum ChatbotEventType {
|
|
2
|
+
CHATBOT_BUTTON_LOADED = "CHATBOT_BUTTON_LOADED",
|
|
3
|
+
CHATBOT_BUTTON_CLICKED = "CHATBOT_BUTTON_CLICKED",
|
|
4
|
+
CHATBOT_OPENED = "CHATBOT_OPENED",
|
|
5
|
+
CHATBOT_CLOSED = "CHATBOT_CLOSED",
|
|
6
|
+
CHATBOT_APP_READY = "CHATBOT_APP_READY",
|
|
7
|
+
CHATBOT_LOADED = "CHATBOT_LOADED",
|
|
8
|
+
CHAT_INITIALIZED = "CHAT_INITIALIZED",
|
|
9
|
+
SESSION_REFRESHED = "SESSION_REFRESHED",
|
|
10
|
+
CHAT_INITIALIZATION_FAILED = "CHAT_INITIALIZATION_FAILED",
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export enum InternalEventType {
|
|
14
|
+
CHAT_MOVED = "CHAT_MOVED",
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type AllEventTypes = ChatbotEventType | InternalEventType;
|
|
18
|
+
|
|
19
|
+
export interface ChatbotEvent {
|
|
20
|
+
type: ChatbotEventType;
|
|
21
|
+
timestamp: number;
|
|
22
|
+
data?: any;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type ChatbotEventHandler = (event: ChatbotEvent) => void;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Platform } from "react-native";
|
|
2
|
+
|
|
3
|
+
declare global {
|
|
4
|
+
interface Window {
|
|
5
|
+
ReactNativeWebView: any;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
declare let global: {
|
|
10
|
+
XMLHttpRequest: any;
|
|
11
|
+
FormData: any;
|
|
12
|
+
originalXMLHttpRequest: any;
|
|
13
|
+
originalFormData: any;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const enableNetworkDebug = () => {
|
|
17
|
+
if (__DEV__) {
|
|
18
|
+
// Enable network request debugging
|
|
19
|
+
global.XMLHttpRequest =
|
|
20
|
+
global.originalXMLHttpRequest || global.XMLHttpRequest;
|
|
21
|
+
global.FormData = global.originalFormData || global.FormData;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const enableWebViewDebug = (webViewRef: any) => {
|
|
26
|
+
if (__DEV__ && Platform.OS === "ios") {
|
|
27
|
+
// Enable console.log from WebView to show in native debugger
|
|
28
|
+
const script = `
|
|
29
|
+
window.onerror = function(message, sourcefile, lineno, colno, error) {
|
|
30
|
+
window.ReactNativeWebView.postMessage(JSON.stringify({
|
|
31
|
+
type: 'ERROR',
|
|
32
|
+
data: { message, sourcefile, lineno, colno, error: error?.toString() }
|
|
33
|
+
}));
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
console = new Proxy(console, {
|
|
37
|
+
get: function(target, property) {
|
|
38
|
+
const origMethod = target[property];
|
|
39
|
+
return function(...args) {
|
|
40
|
+
const logData = args.map(arg =>
|
|
41
|
+
typeof arg === 'object' ? JSON.stringify(arg) : arg
|
|
42
|
+
).join(' ');
|
|
43
|
+
|
|
44
|
+
window.ReactNativeWebView.postMessage(JSON.stringify({
|
|
45
|
+
type: 'CONSOLE',
|
|
46
|
+
level: property,
|
|
47
|
+
data: logData
|
|
48
|
+
}));
|
|
49
|
+
origMethod.apply(target, args);
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
true;`;
|
|
54
|
+
webViewRef.current?.injectJavaScript(script);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Platform, NativeModules } from "react-native";
|
|
2
|
+
|
|
3
|
+
export const openDebugMenu = () => {
|
|
4
|
+
if (Platform.OS === "ios") {
|
|
5
|
+
NativeModules.DevMenu.show();
|
|
6
|
+
}
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const openDebuggerFromApp = () => {
|
|
10
|
+
if (Platform.OS === "ios") {
|
|
11
|
+
// For iOS
|
|
12
|
+
NativeModules.DevSettings.setIsDebuggingRemotely(true);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { logger } from "./logger";
|
|
2
|
+
import { ErrorTypes } from "../constants/errorConstants";
|
|
3
|
+
import { Platform } from "react-native";
|
|
4
|
+
import { errorTracker } from "../services/ErrorTrackingService";
|
|
5
|
+
|
|
6
|
+
// Global error handler for uncaught errors and promise rejections
|
|
7
|
+
export const setupGlobalErrorHandlers = () => {
|
|
8
|
+
if (__DEV__) {
|
|
9
|
+
// Handle synchronous errors
|
|
10
|
+
const errorHandler = (error: Error, isFatal?: boolean) => {
|
|
11
|
+
errorTracker.trackError(error, "GlobalErrorHandler", {
|
|
12
|
+
isFatal,
|
|
13
|
+
type: ErrorTypes.RUNTIME_ERROR,
|
|
14
|
+
platform: Platform.OS,
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// Handle promise rejections
|
|
19
|
+
const rejectionHandler = (event: any) => {
|
|
20
|
+
errorTracker.trackError(
|
|
21
|
+
event?.reason || new Error("Unknown Promise Error"),
|
|
22
|
+
"UnhandledPromiseRejection",
|
|
23
|
+
{
|
|
24
|
+
type: ErrorTypes.RUNTIME_ERROR,
|
|
25
|
+
platform: Platform.OS,
|
|
26
|
+
}
|
|
27
|
+
);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// Set up handlers
|
|
31
|
+
if ((global as any).ErrorUtils) {
|
|
32
|
+
const prevHandler = (global as any).ErrorUtils.getGlobalHandler();
|
|
33
|
+
(global as any).ErrorUtils.setGlobalHandler(
|
|
34
|
+
(error: Error, isFatal?: boolean) => {
|
|
35
|
+
errorHandler(error, isFatal);
|
|
36
|
+
prevHandler(error, isFatal);
|
|
37
|
+
}
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Handle promise rejections
|
|
42
|
+
const setupPromiseRejectionTracking = () => {
|
|
43
|
+
const tracking = require("promise/setimmediate/rejection-tracking");
|
|
44
|
+
tracking.enable({
|
|
45
|
+
allRejections: true,
|
|
46
|
+
onUnhandled: (id: number, error: Error) => {
|
|
47
|
+
rejectionHandler({ reason: error });
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
setupPromiseRejectionTracking();
|
|
54
|
+
} catch (error) {
|
|
55
|
+
logger.warn("Promise rejection tracking setup failed:", error);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const logger = {
|
|
2
|
+
error: (message: string, error?: any) => {
|
|
3
|
+
console.error(message, error);
|
|
4
|
+
},
|
|
5
|
+
info: (message: string, data?: any) => {
|
|
6
|
+
console.info(message, data);
|
|
7
|
+
},
|
|
8
|
+
warn: (message: string, data?: any) => {
|
|
9
|
+
console.warn(message, data);
|
|
10
|
+
},
|
|
11
|
+
debug: (message: string, data?: any) => {
|
|
12
|
+
console.log(message, data);
|
|
13
|
+
},
|
|
14
|
+
};
|