@robylon/react-native-sdk 2.0.30 → 2.0.31-staging.1

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 (87) hide show
  1. package/lib/commonjs/Chatbotsdk.js +2 -2
  2. package/lib/commonjs/Chatbotsdk.js.map +1 -1
  3. package/lib/commonjs/FloatingButton/launchers/ImageLauncher.js +1 -1
  4. package/lib/commonjs/FloatingButton/launchers/ImageLauncher.js.map +1 -1
  5. package/lib/commonjs/FloatingButton/launchers/TextLauncher.js +1 -1
  6. package/lib/commonjs/FloatingButton/launchers/TextLauncher.js.map +1 -1
  7. package/lib/commonjs/FloatingButton/launchers/TextualImageLauncher.js +1 -1
  8. package/lib/commonjs/FloatingButton/launchers/TextualImageLauncher.js.map +1 -1
  9. package/lib/commonjs/FloatingButton.js +1 -1
  10. package/lib/commonjs/FloatingButton.js.map +1 -1
  11. package/lib/commonjs/LoadingIndicator.js +1 -1
  12. package/lib/commonjs/LoadingIndicator.js.map +1 -1
  13. package/lib/commonjs/Toast.js +1 -1
  14. package/lib/commonjs/Toast.js.map +1 -1
  15. package/lib/commonjs/components/DebugButton.js +1 -1
  16. package/lib/commonjs/components/DebugButton.js.map +1 -1
  17. package/lib/commonjs/config.js +1 -1
  18. package/lib/commonjs/config.js.map +1 -1
  19. package/lib/commonjs/constants.js +1 -1
  20. package/lib/commonjs/constants.js.map +1 -1
  21. package/lib/commonjs/utils/fileDownload.js +1 -1
  22. package/lib/commonjs/utils/fileDownload.js.map +1 -1
  23. package/lib/commonjs/versions/version.staging.js +1 -1
  24. package/lib/module/Chatbotsdk.js +2 -2
  25. package/lib/module/Chatbotsdk.js.map +1 -1
  26. package/lib/module/FloatingButton/launchers/ImageLauncher.js +1 -1
  27. package/lib/module/FloatingButton/launchers/ImageLauncher.js.map +1 -1
  28. package/lib/module/FloatingButton/launchers/TextLauncher.js +1 -1
  29. package/lib/module/FloatingButton/launchers/TextLauncher.js.map +1 -1
  30. package/lib/module/FloatingButton/launchers/TextualImageLauncher.js +1 -1
  31. package/lib/module/FloatingButton/launchers/TextualImageLauncher.js.map +1 -1
  32. package/lib/module/FloatingButton.js +1 -1
  33. package/lib/module/FloatingButton.js.map +1 -1
  34. package/lib/module/LoadingIndicator.js +1 -1
  35. package/lib/module/LoadingIndicator.js.map +1 -1
  36. package/lib/module/Toast.js +1 -1
  37. package/lib/module/Toast.js.map +1 -1
  38. package/lib/module/components/DebugButton.js +1 -1
  39. package/lib/module/components/DebugButton.js.map +1 -1
  40. package/lib/module/config.js +1 -1
  41. package/lib/module/config.js.map +1 -1
  42. package/lib/module/constants.js +1 -1
  43. package/lib/module/constants.js.map +1 -1
  44. package/lib/module/utils/fileDownload.js +1 -1
  45. package/lib/module/utils/fileDownload.js.map +1 -1
  46. package/lib/module/versions/version.staging.js +1 -1
  47. package/lib/typescript/Chatbotsdk.d.ts.map +1 -1
  48. package/lib/typescript/utils/fileDownload.d.ts +3 -2
  49. package/lib/typescript/utils/fileDownload.d.ts.map +1 -1
  50. package/lib/typescript/versions/version.staging.d.ts +1 -1
  51. package/package.json +6 -3
  52. package/src/Chatbotsdk.tsx +946 -0
  53. package/src/FloatingButton/launchers/ImageLauncher.tsx +75 -0
  54. package/src/FloatingButton/launchers/TextLauncher.tsx +84 -0
  55. package/src/FloatingButton/launchers/TextualImageLauncher.tsx +133 -0
  56. package/src/FloatingButton.tsx +97 -0
  57. package/src/LoadingIndicator.tsx +11 -0
  58. package/src/Toast.tsx +65 -0
  59. package/src/components/DebugButton.tsx +46 -0
  60. package/src/components/ErrorBoundary.tsx +38 -0
  61. package/src/config.ts +4 -0
  62. package/src/constants/errorConstants.ts +21 -0
  63. package/src/constants/fontStyles.ts +3 -0
  64. package/src/constants.ts +5 -0
  65. package/src/global.d.ts +11 -0
  66. package/src/hooks/useChatbotEvents.ts +93 -0
  67. package/src/index.tsx +10 -0
  68. package/src/openChatbot.ts +11 -0
  69. package/src/openChatbot.tsx +0 -0
  70. package/src/services/ErrorTrackingService.ts +217 -0
  71. package/src/types/events.ts +28 -0
  72. package/src/types/react-native-flipper-performance-plugin.d.ts +3 -0
  73. package/src/types/react-native-globals.d.ts +10 -0
  74. package/src/utils/animations.ts +120 -0
  75. package/src/utils/colorUtils.ts +35 -0
  76. package/src/utils/cookieUtils.ts +7 -0
  77. package/src/utils/debugConfig.ts +56 -0
  78. package/src/utils/debugMenu.ts +14 -0
  79. package/src/utils/errorHandler.ts +58 -0
  80. package/src/utils/fileDownload.ts +192 -0
  81. package/src/utils/logger.ts +14 -0
  82. package/src/utils/systemInfo.ts +110 -0
  83. package/src/utils/webViewStorage.ts +62 -0
  84. package/src/version.ts +2 -0
  85. package/src/versions/version.dev.ts +2 -0
  86. package/src/versions/version.production.ts +2 -0
  87. package/src/versions/version.staging.ts +2 -0
@@ -0,0 +1,192 @@
1
+ /**
2
+ * File: src/utils/fileDownload.ts
3
+ * Utility functions for handling file downloads
4
+ */
5
+
6
+ import { Linking, Platform, Share } from "react-native";
7
+ import { logger } from "./logger";
8
+
9
+ export interface DownloadRequest {
10
+ url: string;
11
+ filename?: string;
12
+ inPlace?: boolean;
13
+ }
14
+
15
+ const normalizeUrl = (url: string): string => {
16
+ return url?.trim();
17
+ };
18
+
19
+ const sanitizeFileName = (filename?: string): string => {
20
+ const fallbackName = `chat-transcript-${Date.now()}.pdf`;
21
+ const trimmedName = filename?.trim();
22
+ if (!trimmedName) return fallbackName;
23
+ return trimmedName.replace(/[<>:"/\\|?*\x00-\x1F]/g, "_");
24
+ };
25
+
26
+ const getBlobUtilModule = (): any => {
27
+ try {
28
+ // Lazy load so consumers without native linking don't crash at startup.
29
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
30
+ return require("react-native-blob-util")?.default;
31
+ } catch (error) {
32
+ logger.warn("react-native-blob-util is unavailable", {
33
+ error: error instanceof Error ? error?.message : String(error),
34
+ });
35
+ return null;
36
+ }
37
+ };
38
+
39
+ const isValidHttpUrl = (url: string): boolean => {
40
+ return /^https?:\/\//i.test(url);
41
+ };
42
+
43
+ const openUrlWithFallback = async (url: string): Promise<void> => {
44
+ try {
45
+ await Linking.openURL(url);
46
+ return;
47
+ } catch (primaryError) {
48
+ logger.warn("Primary URL open failed, trying browser fallback", {
49
+ url,
50
+ primaryError:
51
+ primaryError instanceof Error
52
+ ? primaryError?.message
53
+ : String(primaryError),
54
+ });
55
+ }
56
+
57
+ await Linking.openURL(`https://docs.google.com/viewer?url=${encodeURIComponent(url)}`);
58
+ };
59
+
60
+ const downloadOnAndroid = async (url: string, filename: string): Promise<void> => {
61
+ const blobUtil = getBlobUtilModule();
62
+ if (!blobUtil) {
63
+ throw new Error("react-native-blob-util module not available on Android");
64
+ }
65
+ const { fs, config } = blobUtil;
66
+ const downloadPath = `${fs.dirs.DownloadDir}/${filename}`;
67
+ await config({
68
+ fileCache: true,
69
+ path: downloadPath,
70
+ addAndroidDownloads: {
71
+ useDownloadManager: true,
72
+ notification: true,
73
+ title: filename,
74
+ description: "Downloading transcript",
75
+ mime: "application/pdf",
76
+ mediaScannable: true,
77
+ path: downloadPath,
78
+ },
79
+ }).fetch("GET", url);
80
+ };
81
+
82
+ const downloadOniOS = async (url: string, filename: string): Promise<void> => {
83
+ const blobUtil = getBlobUtilModule();
84
+ if (!blobUtil) {
85
+ throw new Error("react-native-blob-util module not available on iOS");
86
+ }
87
+ const { fs, config } = blobUtil;
88
+ const iosPath = `${fs.dirs.DocumentDir}/${filename}`;
89
+ await config({
90
+ fileCache: true,
91
+ path: iosPath,
92
+ }).fetch("GET", url);
93
+ await Share.share({
94
+ url: `file://${iosPath}`,
95
+ message: filename,
96
+ title: filename,
97
+ });
98
+ };
99
+
100
+ const downloadWithNativeStorage = async (
101
+ url: string,
102
+ filename?: string
103
+ ): Promise<void> => {
104
+ const safeName = sanitizeFileName(filename);
105
+ if (Platform.OS === "android") {
106
+ await downloadOnAndroid(url, safeName);
107
+ return;
108
+ }
109
+ await downloadOniOS(url, safeName);
110
+ };
111
+
112
+ const shouldUseInPlaceDownload = (downloadRequest?: DownloadRequest): boolean => {
113
+ return downloadRequest?.inPlace === true;
114
+ };
115
+
116
+ /**
117
+ * Downloads a file using native storage when possible
118
+ * @param url - The URL of the file to download
119
+ * @param filename - Optional filename for the download
120
+ */
121
+ export const downloadFile = async (
122
+ url: string,
123
+ filename?: string,
124
+ inPlace?: boolean
125
+ ): Promise<void> => {
126
+ try {
127
+ const normalizedUrl = normalizeUrl(url);
128
+ logger.debug("Initiating file download", { url: normalizedUrl, filename });
129
+
130
+ // Validate URL
131
+ if (!normalizedUrl || typeof normalizedUrl !== "string") {
132
+ throw new Error("Invalid URL provided for download");
133
+ }
134
+
135
+ if (!isValidHttpUrl(normalizedUrl)) {
136
+ throw new Error("Download URL must be an http/https URL");
137
+ }
138
+
139
+ if (inPlace) {
140
+ try {
141
+ await downloadWithNativeStorage(normalizedUrl, filename);
142
+ logger.debug("File downloaded with native storage flow");
143
+ } catch (nativeDownloadError) {
144
+ logger.warn("Native download failed, falling back to URL open", {
145
+ url: normalizedUrl,
146
+ nativeDownloadError:
147
+ nativeDownloadError instanceof Error
148
+ ? nativeDownloadError?.message
149
+ : String(nativeDownloadError),
150
+ });
151
+ await openUrlWithFallback(normalizedUrl);
152
+ logger.debug("File download opened with fallback browser flow");
153
+ }
154
+ return;
155
+ }
156
+
157
+ await openUrlWithFallback(normalizedUrl);
158
+ logger.debug("File download opened with legacy URL flow");
159
+ } catch (error) {
160
+ logger.error("File download failed", {
161
+ url,
162
+ filename,
163
+ error: error instanceof Error ? error?.message : String(error),
164
+ });
165
+ throw error;
166
+ }
167
+ };
168
+
169
+ /**
170
+ * Handles download request from WebView post message
171
+ * @param downloadRequest - The download request object
172
+ */
173
+ export const handleDownloadRequest = async (
174
+ downloadRequest: DownloadRequest
175
+ ): Promise<void> => {
176
+ const { url, filename } = downloadRequest;
177
+
178
+ if (!url) {
179
+ logger.error("Download request missing URL");
180
+ return;
181
+ }
182
+
183
+ try {
184
+ await downloadFile(url, filename, shouldUseInPlaceDownload(downloadRequest));
185
+ } catch (error) {
186
+ logger.error("Failed to handle download request", {
187
+ downloadRequest,
188
+ error,
189
+ });
190
+ // Don't re-throw to avoid breaking the WebView message handling
191
+ }
192
+ };
@@ -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
+ };
@@ -0,0 +1,110 @@
1
+ import { Platform, Dimensions, PixelRatio } from "react-native";
2
+ import { SDK_VERSION } from "../version";
3
+
4
+ interface ScreenSize {
5
+ width: number;
6
+ height: number;
7
+ }
8
+
9
+ interface SystemInfo {
10
+ platform: string;
11
+ os: string;
12
+ browser: string;
13
+ browser_version: string | null;
14
+ browser_language: string | null;
15
+ sdk_version: string;
16
+ device: string;
17
+ screen_size: ScreenSize;
18
+ }
19
+
20
+ // Get device type based on platform and screen dimensions
21
+ const getDeviceType = (): string => {
22
+ const { width, height } = Dimensions.get("window");
23
+ const aspectRatio = height / width;
24
+
25
+ if (Platform.OS === "ios") {
26
+ return Platform.isPad ? "iPad" : "iPhone";
27
+ } else if (Platform.OS === "android") {
28
+ return aspectRatio < 1.6 ? "Android Tablet" : "Android Phone";
29
+ }
30
+ return "Desktop";
31
+ };
32
+
33
+ // Get screen dimensions with pixel ratio
34
+ const getScreenSize = (): ScreenSize => {
35
+ return {
36
+ width: Math.round(Dimensions.get("window").width * PixelRatio.get()),
37
+ height: Math.round(Dimensions.get("window").height * PixelRatio.get()),
38
+ };
39
+ };
40
+
41
+ // Get browser detection script
42
+ export const getBrowserAndOSInfoScript = (): string => {
43
+ return `
44
+ function getOSAndBrowser() {
45
+ const userAgent = navigator.userAgent;
46
+
47
+ // OS Detection
48
+ let os = "unknown";
49
+ if (userAgent.indexOf("Win") !== -1) os = "Windows";
50
+ else if (userAgent.indexOf("Mac") !== -1) os = "MacOS";
51
+ else if (userAgent.indexOf("Linux") !== -1) os = "Linux";
52
+ else if (userAgent.indexOf("Android") !== -1) os = "Android";
53
+ else if (userAgent.indexOf("like Mac") !== -1) os = "iOS";
54
+
55
+ // Browser Detection
56
+ let browser = "unknown";
57
+ let browserVersion = null;
58
+ if (userAgent.indexOf("Chrome") !== -1) {
59
+ browser = "Chrome";
60
+ const chromeMatch = userAgent.match(/Chrome\\/([0-9.]+)/);
61
+ browserVersion = chromeMatch ? chromeMatch[1] : null;
62
+ } else if (userAgent.indexOf("Safari") !== -1) {
63
+ browser = "Safari";
64
+ const safariMatch = userAgent.match(/Version\\/([0-9.]+)/);
65
+ browserVersion = safariMatch ? safariMatch[1] : null;
66
+ } else if (userAgent.indexOf("Firefox") !== -1) {
67
+ browser = "Firefox";
68
+ const firefoxMatch = userAgent.match(/Firefox\\/([0-9.]+)/);
69
+ browserVersion = firefoxMatch ? firefoxMatch[1] : null;
70
+ } else if (userAgent.indexOf("Edge") !== -1) {
71
+ browser = "Edge";
72
+ const edgeMatch = userAgent.match(/Edge\\/([0-9.]+)/);
73
+ browserVersion = edgeMatch ? edgeMatch[1] : null;
74
+ } else if (userAgent.indexOf("MSIE") !== -1 || userAgent.indexOf("Trident/") !== -1) {
75
+ browser = "IE";
76
+ const ieMatch = userAgent.match(/(?:MSIE |rv:)([0-9.]+)/);
77
+ browserVersion = ieMatch ? ieMatch[1] : null;
78
+ }
79
+
80
+ // Browser Language
81
+ const browserLanguage = navigator.language || navigator.languages?.[0] || null;
82
+
83
+ window.ReactNativeWebView.postMessage(JSON.stringify({
84
+ type: 'SYSTEM_INFO',
85
+ data: { os, browser, browser_version: browserVersion, browser_language: browserLanguage }
86
+ }));
87
+ }
88
+ getOSAndBrowser();
89
+ true;
90
+ `;
91
+ };
92
+
93
+ // Get complete system information
94
+ export const getSystemInfo = (webViewSystemInfo: {
95
+ os: string;
96
+ browser: string;
97
+ browser_version?: string | null;
98
+ browser_language?: string | null;
99
+ }): SystemInfo => {
100
+ return {
101
+ platform: Platform.OS,
102
+ os: webViewSystemInfo.os || Platform.OS,
103
+ browser: webViewSystemInfo.browser || "WebView",
104
+ browser_version: webViewSystemInfo.browser_version || null,
105
+ browser_language: webViewSystemInfo.browser_language || null,
106
+ sdk_version: SDK_VERSION,
107
+ device: getDeviceType(),
108
+ screen_size: getScreenSize(),
109
+ };
110
+ };
@@ -0,0 +1,62 @@
1
+ import { logger } from "./logger";
2
+
3
+ export enum StorageMessageType {
4
+ GET_STORAGE = "GET_STORAGE",
5
+ SET_STORAGE = "SET_STORAGE",
6
+ STORAGE_READY = "STORAGE_READY",
7
+ STORAGE_ERROR = "STORAGE_ERROR",
8
+ STORAGE_RESPONSE = "STORAGE_RESPONSE",
9
+ }
10
+
11
+ export interface StorageMessage {
12
+ type: StorageMessageType;
13
+ key?: string;
14
+ value?: string;
15
+ error?: string;
16
+ }
17
+
18
+ export const getStorageScript = () => `
19
+ window.handleStorageOperation = function(message) {
20
+ try {
21
+ switch(message.type) {
22
+ case '${StorageMessageType.GET_STORAGE}':
23
+ const value = localStorage.getItem(message.key);
24
+ window.ReactNativeWebView.postMessage(JSON.stringify({
25
+ type: '${StorageMessageType.STORAGE_RESPONSE}',
26
+ key: message.key,
27
+ value: value
28
+ }));
29
+ break;
30
+ case '${StorageMessageType.SET_STORAGE}':
31
+ localStorage.setItem(message.key, message.value);
32
+ window.ReactNativeWebView.postMessage(JSON.stringify({
33
+ type: '${StorageMessageType.STORAGE_RESPONSE}',
34
+ key: message.key,
35
+ value: message.value
36
+ }));
37
+ break;
38
+ }
39
+ } catch (error) {
40
+ window.ReactNativeWebView.postMessage(JSON.stringify({
41
+ type: '${StorageMessageType.STORAGE_ERROR}',
42
+ error: error.message
43
+ }));
44
+ }
45
+ };
46
+
47
+ window.ReactNativeWebView.postMessage(JSON.stringify({
48
+ type: '${StorageMessageType.STORAGE_READY}'
49
+ }));
50
+ `;
51
+
52
+ export const createStorageMessage = (
53
+ type: StorageMessageType,
54
+ key?: string,
55
+ value?: string
56
+ ): string => {
57
+ return `window.handleStorageOperation(${JSON.stringify({
58
+ type,
59
+ key,
60
+ value,
61
+ })});`;
62
+ };
package/src/version.ts ADDED
@@ -0,0 +1,2 @@
1
+ // This file is auto-generated. Do not modify it manually.
2
+ export { SDK_VERSION } from './versions/version.staging';
@@ -0,0 +1,2 @@
1
+ // This file is auto-generated. Do not modify it manually.
2
+ export const SDK_VERSION = '2.0.22-dev.0';
@@ -0,0 +1,2 @@
1
+ // This file is auto-generated. Do not modify it manually.
2
+ export const SDK_VERSION = "0.0.0";
@@ -0,0 +1,2 @@
1
+ // This file is auto-generated. Do not modify it manually.
2
+ export const SDK_VERSION = '2.0.31-staging.1';