feeddo-react-native 0.0.0-stage → 0.1.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 (225) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +401 -2
  3. package/android/build.gradle +39 -0
  4. package/android/src/main/AndroidManifest.xml +1 -0
  5. package/android/src/main/java/dev/feeddo/reactnative/FeeddoReactNativeModule.java +380 -0
  6. package/android/src/main/java/dev/feeddo/reactnative/FeeddoReactNativePackage.java +25 -0
  7. package/dist/Feeddo.d.ts +131 -0
  8. package/dist/Feeddo.d.ts.map +1 -0
  9. package/dist/Feeddo.js +176 -0
  10. package/dist/Feeddo.js.map +1 -0
  11. package/dist/FeeddoClient.d.ts +151 -0
  12. package/dist/FeeddoClient.d.ts.map +1 -0
  13. package/dist/FeeddoClient.js +690 -0
  14. package/dist/FeeddoClient.js.map +1 -0
  15. package/dist/FeeddoProvider.d.ts +23 -0
  16. package/dist/FeeddoProvider.d.ts.map +1 -0
  17. package/dist/FeeddoProvider.js +76 -0
  18. package/dist/FeeddoProvider.js.map +1 -0
  19. package/dist/config/FeeddoConfig.d.ts +10 -0
  20. package/dist/config/FeeddoConfig.d.ts.map +1 -0
  21. package/dist/config/FeeddoConfig.js +10 -0
  22. package/dist/config/FeeddoConfig.js.map +1 -0
  23. package/dist/index.d.ts +36 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +38 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/models/Conversation.d.ts +27 -0
  28. package/dist/models/Conversation.d.ts.map +1 -0
  29. package/dist/models/Conversation.js +24 -0
  30. package/dist/models/Conversation.js.map +1 -0
  31. package/dist/models/EndUser.d.ts +49 -0
  32. package/dist/models/EndUser.d.ts.map +1 -0
  33. package/dist/models/EndUser.js +2 -0
  34. package/dist/models/EndUser.js.map +1 -0
  35. package/dist/models/FeeddoNotification.d.ts +15 -0
  36. package/dist/models/FeeddoNotification.d.ts.map +1 -0
  37. package/dist/models/FeeddoNotification.js +15 -0
  38. package/dist/models/FeeddoNotification.js.map +1 -0
  39. package/dist/models/HomeData.d.ts +16 -0
  40. package/dist/models/HomeData.d.ts.map +1 -0
  41. package/dist/models/HomeData.js +19 -0
  42. package/dist/models/HomeData.js.map +1 -0
  43. package/dist/models/Message.d.ts +12 -0
  44. package/dist/models/Message.d.ts.map +1 -0
  45. package/dist/models/Message.js +25 -0
  46. package/dist/models/Message.js.map +1 -0
  47. package/dist/models/PushProvider.d.ts +14 -0
  48. package/dist/models/PushProvider.d.ts.map +1 -0
  49. package/dist/models/PushProvider.js +9 -0
  50. package/dist/models/PushProvider.js.map +1 -0
  51. package/dist/models/Task.d.ts +17 -0
  52. package/dist/models/Task.d.ts.map +1 -0
  53. package/dist/models/Task.js +22 -0
  54. package/dist/models/Task.js.map +1 -0
  55. package/dist/models/TaskComment.d.ts +11 -0
  56. package/dist/models/TaskComment.d.ts.map +1 -0
  57. package/dist/models/TaskComment.js +27 -0
  58. package/dist/models/TaskComment.js.map +1 -0
  59. package/dist/models/Ticket.d.ts +13 -0
  60. package/dist/models/Ticket.d.ts.map +1 -0
  61. package/dist/models/Ticket.js +14 -0
  62. package/dist/models/Ticket.js.map +1 -0
  63. package/dist/native/FeeddoNative.d.ts +58 -0
  64. package/dist/native/FeeddoNative.d.ts.map +1 -0
  65. package/dist/native/FeeddoNative.js +22 -0
  66. package/dist/native/FeeddoNative.js.map +1 -0
  67. package/dist/push/FeeddoPushNotificationApns.d.ts +73 -0
  68. package/dist/push/FeeddoPushNotificationApns.d.ts.map +1 -0
  69. package/dist/push/FeeddoPushNotificationApns.js +301 -0
  70. package/dist/push/FeeddoPushNotificationApns.js.map +1 -0
  71. package/dist/services/ApiService.d.ts +64 -0
  72. package/dist/services/ApiService.d.ts.map +1 -0
  73. package/dist/services/ApiService.js +406 -0
  74. package/dist/services/ApiService.js.map +1 -0
  75. package/dist/services/ConversationService.d.ts +45 -0
  76. package/dist/services/ConversationService.d.ts.map +1 -0
  77. package/dist/services/ConversationService.js +259 -0
  78. package/dist/services/ConversationService.js.map +1 -0
  79. package/dist/services/WebSocketService.d.ts +26 -0
  80. package/dist/services/WebSocketService.d.ts.map +1 -0
  81. package/dist/services/WebSocketService.js +157 -0
  82. package/dist/services/WebSocketService.js.map +1 -0
  83. package/dist/theme/FeeddoTheme.d.ts +31 -0
  84. package/dist/theme/FeeddoTheme.d.ts.map +1 -0
  85. package/dist/theme/FeeddoTheme.js +60 -0
  86. package/dist/theme/FeeddoTheme.js.map +1 -0
  87. package/dist/ui/FeeddoFeedbackCard.d.ts +15 -0
  88. package/dist/ui/FeeddoFeedbackCard.d.ts.map +1 -0
  89. package/dist/ui/FeeddoFeedbackCard.js +188 -0
  90. package/dist/ui/FeeddoFeedbackCard.js.map +1 -0
  91. package/dist/ui/FeeddoModal.d.ts +20 -0
  92. package/dist/ui/FeeddoModal.d.ts.map +1 -0
  93. package/dist/ui/FeeddoModal.js +180 -0
  94. package/dist/ui/FeeddoModal.js.map +1 -0
  95. package/dist/ui/components/AttachmentPreview.d.ts +10 -0
  96. package/dist/ui/components/AttachmentPreview.d.ts.map +1 -0
  97. package/dist/ui/components/AttachmentPreview.js +143 -0
  98. package/dist/ui/components/AttachmentPreview.js.map +1 -0
  99. package/dist/ui/components/ChatInputArea.d.ts +16 -0
  100. package/dist/ui/components/ChatInputArea.d.ts.map +1 -0
  101. package/dist/ui/components/ChatInputArea.js +85 -0
  102. package/dist/ui/components/ChatInputArea.js.map +1 -0
  103. package/dist/ui/components/FeeddoIcon.d.ts +10 -0
  104. package/dist/ui/components/FeeddoIcon.d.ts.map +1 -0
  105. package/dist/ui/components/FeeddoIcon.js +690 -0
  106. package/dist/ui/components/FeeddoIcon.js.map +1 -0
  107. package/dist/ui/components/FeeddoNotificationBadge.d.ts +14 -0
  108. package/dist/ui/components/FeeddoNotificationBadge.d.ts.map +1 -0
  109. package/dist/ui/components/FeeddoNotificationBadge.js +171 -0
  110. package/dist/ui/components/FeeddoNotificationBadge.js.map +1 -0
  111. package/dist/ui/components/MessageBubble.d.ts +13 -0
  112. package/dist/ui/components/MessageBubble.d.ts.map +1 -0
  113. package/dist/ui/components/MessageBubble.js +163 -0
  114. package/dist/ui/components/MessageBubble.js.map +1 -0
  115. package/dist/ui/components/NotificationsSheet.d.ts +10 -0
  116. package/dist/ui/components/NotificationsSheet.d.ts.map +1 -0
  117. package/dist/ui/components/NotificationsSheet.js +252 -0
  118. package/dist/ui/components/NotificationsSheet.js.map +1 -0
  119. package/dist/ui/components/RatingWidget.d.ts +11 -0
  120. package/dist/ui/components/RatingWidget.d.ts.map +1 -0
  121. package/dist/ui/components/RatingWidget.js +34 -0
  122. package/dist/ui/components/RatingWidget.js.map +1 -0
  123. package/dist/ui/components/TaskCard.d.ts +12 -0
  124. package/dist/ui/components/TaskCard.d.ts.map +1 -0
  125. package/dist/ui/components/TaskCard.js +210 -0
  126. package/dist/ui/components/TaskCard.js.map +1 -0
  127. package/dist/ui/components/TaskDetailsSheet.d.ts +15 -0
  128. package/dist/ui/components/TaskDetailsSheet.d.ts.map +1 -0
  129. package/dist/ui/components/TaskDetailsSheet.js +577 -0
  130. package/dist/ui/components/TaskDetailsSheet.js.map +1 -0
  131. package/dist/ui/components/TicketCard.d.ts +11 -0
  132. package/dist/ui/components/TicketCard.d.ts.map +1 -0
  133. package/dist/ui/components/TicketCard.js +100 -0
  134. package/dist/ui/components/TicketCard.js.map +1 -0
  135. package/dist/ui/components/TicketDetailsSheet.d.ts +14 -0
  136. package/dist/ui/components/TicketDetailsSheet.d.ts.map +1 -0
  137. package/dist/ui/components/TicketDetailsSheet.js +254 -0
  138. package/dist/ui/components/TicketDetailsSheet.js.map +1 -0
  139. package/dist/ui/components/TypingIndicator.d.ts +10 -0
  140. package/dist/ui/components/TypingIndicator.d.ts.map +1 -0
  141. package/dist/ui/components/TypingIndicator.js +77 -0
  142. package/dist/ui/components/TypingIndicator.js.map +1 -0
  143. package/dist/ui/screens/FeeddoChatScreen.d.ts +13 -0
  144. package/dist/ui/screens/FeeddoChatScreen.d.ts.map +1 -0
  145. package/dist/ui/screens/FeeddoChatScreen.js +681 -0
  146. package/dist/ui/screens/FeeddoChatScreen.js.map +1 -0
  147. package/dist/ui/screens/FeeddoHomeScreen.d.ts +15 -0
  148. package/dist/ui/screens/FeeddoHomeScreen.d.ts.map +1 -0
  149. package/dist/ui/screens/FeeddoHomeScreen.js +653 -0
  150. package/dist/ui/screens/FeeddoHomeScreen.js.map +1 -0
  151. package/dist/ui/screens/FeeddoMessagesScreen.d.ts +12 -0
  152. package/dist/ui/screens/FeeddoMessagesScreen.d.ts.map +1 -0
  153. package/dist/ui/screens/FeeddoMessagesScreen.js +326 -0
  154. package/dist/ui/screens/FeeddoMessagesScreen.js.map +1 -0
  155. package/dist/ui/screens/FeeddoTasksScreen.d.ts +13 -0
  156. package/dist/ui/screens/FeeddoTasksScreen.d.ts.map +1 -0
  157. package/dist/ui/screens/FeeddoTasksScreen.js +517 -0
  158. package/dist/ui/screens/FeeddoTasksScreen.js.map +1 -0
  159. package/dist/ui/screens/FeeddoTicketsScreen.d.ts +10 -0
  160. package/dist/ui/screens/FeeddoTicketsScreen.d.ts.map +1 -0
  161. package/dist/ui/screens/FeeddoTicketsScreen.js +112 -0
  162. package/dist/ui/screens/FeeddoTicketsScreen.js.map +1 -0
  163. package/dist/utils/DeviceInfoHelper.d.ts +29 -0
  164. package/dist/utils/DeviceInfoHelper.d.ts.map +1 -0
  165. package/dist/utils/DeviceInfoHelper.js +190 -0
  166. package/dist/utils/DeviceInfoHelper.js.map +1 -0
  167. package/dist/utils/MediaHelper.d.ts +20 -0
  168. package/dist/utils/MediaHelper.d.ts.map +1 -0
  169. package/dist/utils/MediaHelper.js +92 -0
  170. package/dist/utils/MediaHelper.js.map +1 -0
  171. package/dist/utils/NotificationSupport.d.ts +22 -0
  172. package/dist/utils/NotificationSupport.d.ts.map +1 -0
  173. package/dist/utils/NotificationSupport.js +211 -0
  174. package/dist/utils/NotificationSupport.js.map +1 -0
  175. package/dist/utils/StorageHelper.d.ts +65 -0
  176. package/dist/utils/StorageHelper.d.ts.map +1 -0
  177. package/dist/utils/StorageHelper.js +273 -0
  178. package/dist/utils/StorageHelper.js.map +1 -0
  179. package/feeddo-react-native.podspec +26 -0
  180. package/ios/FeeddoReactNativeModule.h +8 -0
  181. package/ios/FeeddoReactNativeModule.m +831 -0
  182. package/package.json +56 -4
  183. package/src/Feeddo.ts +247 -0
  184. package/src/FeeddoClient.ts +895 -0
  185. package/src/FeeddoProvider.tsx +139 -0
  186. package/src/config/FeeddoConfig.ts +9 -0
  187. package/src/index.ts +67 -0
  188. package/src/models/Conversation.ts +50 -0
  189. package/src/models/EndUser.ts +65 -0
  190. package/src/models/FeeddoNotification.ts +29 -0
  191. package/src/models/HomeData.ts +33 -0
  192. package/src/models/Message.ts +36 -0
  193. package/src/models/PushProvider.ts +15 -0
  194. package/src/models/Task.ts +40 -0
  195. package/src/models/TaskComment.ts +36 -0
  196. package/src/models/Ticket.ts +25 -0
  197. package/src/native/FeeddoNative.ts +80 -0
  198. package/src/push/FeeddoPushNotificationApns.ts +362 -0
  199. package/src/services/ApiService.ts +456 -0
  200. package/src/services/ConversationService.ts +305 -0
  201. package/src/services/WebSocketService.ts +185 -0
  202. package/src/theme/FeeddoTheme.ts +85 -0
  203. package/src/ui/FeeddoFeedbackCard.tsx +245 -0
  204. package/src/ui/FeeddoModal.tsx +309 -0
  205. package/src/ui/components/AttachmentPreview.tsx +192 -0
  206. package/src/ui/components/ChatInputArea.tsx +154 -0
  207. package/src/ui/components/FeeddoIcon.tsx +903 -0
  208. package/src/ui/components/FeeddoNotificationBadge.tsx +234 -0
  209. package/src/ui/components/MessageBubble.tsx +223 -0
  210. package/src/ui/components/NotificationsSheet.tsx +324 -0
  211. package/src/ui/components/RatingWidget.tsx +64 -0
  212. package/src/ui/components/TaskCard.tsx +259 -0
  213. package/src/ui/components/TaskDetailsSheet.tsx +747 -0
  214. package/src/ui/components/TicketCard.tsx +128 -0
  215. package/src/ui/components/TicketDetailsSheet.tsx +324 -0
  216. package/src/ui/components/TypingIndicator.tsx +104 -0
  217. package/src/ui/screens/FeeddoChatScreen.tsx +877 -0
  218. package/src/ui/screens/FeeddoHomeScreen.tsx +824 -0
  219. package/src/ui/screens/FeeddoMessagesScreen.tsx +414 -0
  220. package/src/ui/screens/FeeddoTasksScreen.tsx +671 -0
  221. package/src/ui/screens/FeeddoTicketsScreen.tsx +164 -0
  222. package/src/utils/DeviceInfoHelper.ts +209 -0
  223. package/src/utils/MediaHelper.ts +105 -0
  224. package/src/utils/NotificationSupport.ts +233 -0
  225. package/src/utils/StorageHelper.ts +305 -0
@@ -0,0 +1,164 @@
1
+ import React, { useState, useEffect } from 'react';
2
+ import {
3
+ View,
4
+ Text,
5
+ StyleSheet,
6
+ TouchableOpacity,
7
+ FlatList,
8
+ ActivityIndicator,
9
+ SafeAreaView,
10
+ } from 'react-native';
11
+ import { Ticket } from '../../models/Ticket';
12
+ import { FeeddoTheme } from '../../theme/FeeddoTheme';
13
+ import { FeeddoIcon } from '../components/FeeddoIcon';
14
+ import { TicketCard } from '../components/TicketCard';
15
+ import { TicketDetailsSheet } from '../components/TicketDetailsSheet';
16
+ import { FeeddoInternal } from '../../FeeddoClient';
17
+
18
+ interface FeeddoTicketsScreenProps {
19
+ theme: FeeddoTheme;
20
+ onBack: () => void;
21
+ onOpenConversation?: (conversationId: string) => void;
22
+ }
23
+
24
+ export const FeeddoTicketsScreen: React.FC<FeeddoTicketsScreenProps> = ({
25
+ theme,
26
+ onBack,
27
+ onOpenConversation,
28
+ }) => {
29
+ const [tickets, setTickets] = useState<Ticket[]>([]);
30
+ const [isLoading, setIsLoading] = useState<boolean>(true);
31
+ const [error, setError] = useState<string | null>(null);
32
+ const [selectedTicket, setSelectedTicket] = useState<Ticket | null>(null);
33
+
34
+ useEffect(() => {
35
+ loadTickets();
36
+ }, []);
37
+
38
+ const loadTickets = async () => {
39
+ setIsLoading(true);
40
+ setError(null);
41
+ try {
42
+ const list = await FeeddoInternal.instance.getTickets();
43
+ setTickets(list);
44
+ } catch (e: any) {
45
+ setError(e?.message || String(e));
46
+ } finally {
47
+ setIsLoading(false);
48
+ }
49
+ };
50
+
51
+ return (
52
+ <SafeAreaView style={[styles.container, { backgroundColor: theme.colors.background }]}>
53
+ {/* AppBar */}
54
+ <View
55
+ style={[
56
+ styles.appBar,
57
+ {
58
+ backgroundColor: theme.colors.appBarBackground,
59
+ borderBottomColor: `${theme.colors.divider}1A`,
60
+ },
61
+ ]}
62
+ >
63
+ <TouchableOpacity activeOpacity={0.8} onPress={onBack} style={styles.backButton}>
64
+ <FeeddoIcon name="arrow_back" size={20} color={theme.colors.iconColor} />
65
+ </TouchableOpacity>
66
+ <Text style={[styles.appBarTitle, { color: theme.colors.textPrimary }]}>
67
+ Tickets
68
+ </Text>
69
+ </View>
70
+
71
+ {/* Content */}
72
+ {isLoading ? (
73
+ <View style={styles.centerContainer}>
74
+ <ActivityIndicator size="large" color={theme.colors.primary} />
75
+ </View>
76
+ ) : error ? (
77
+ <View style={styles.centerContainer}>
78
+ <Text style={[styles.errorText, { color: theme.colors.textPrimary }]}>
79
+ {`Error: ${error}`}
80
+ </Text>
81
+ <TouchableOpacity onPress={loadTickets} style={styles.retryButton}>
82
+ <Text style={[styles.retryText, { color: theme.colors.primary }]}>Retry</Text>
83
+ </TouchableOpacity>
84
+ </View>
85
+ ) : tickets.length === 0 ? (
86
+ <View style={styles.centerContainer}>
87
+ <Text style={[styles.emptyText, { color: theme.colors.textPrimary }]}>
88
+ No tickets yet
89
+ </Text>
90
+ </View>
91
+ ) : (
92
+ <FlatList
93
+ data={tickets}
94
+ keyExtractor={(item) => item.id}
95
+ contentContainerStyle={styles.listContent}
96
+ ItemSeparatorComponent={() => <View style={{ height: 12 }} />}
97
+ renderItem={({ item }) => (
98
+ <TicketCard
99
+ ticket={item}
100
+ theme={theme}
101
+ onTap={() => setSelectedTicket(item)}
102
+ />
103
+ )}
104
+ />
105
+ )}
106
+
107
+ {/* Ticket Details Sheet */}
108
+ <TicketDetailsSheet
109
+ visible={Boolean(selectedTicket)}
110
+ ticket={selectedTicket ?? undefined}
111
+ onClose={() => setSelectedTicket(null)}
112
+ onOpenConversation={onOpenConversation}
113
+ theme={theme}
114
+ />
115
+ </SafeAreaView>
116
+ );
117
+ };
118
+
119
+ const styles = StyleSheet.create({
120
+ container: {
121
+ flex: 1,
122
+ },
123
+ appBar: {
124
+ flexDirection: 'row',
125
+ alignItems: 'center',
126
+ paddingHorizontal: 16,
127
+ paddingVertical: 14,
128
+ borderBottomWidth: 1,
129
+ },
130
+ backButton: {
131
+ padding: 6,
132
+ marginRight: 10,
133
+ },
134
+ appBarTitle: {
135
+ fontSize: 20,
136
+ fontWeight: '700',
137
+ },
138
+ centerContainer: {
139
+ flex: 1,
140
+ alignItems: 'center',
141
+ justifyContent: 'center',
142
+ padding: 16,
143
+ },
144
+ errorText: {
145
+ fontSize: 14,
146
+ textAlign: 'center',
147
+ },
148
+ retryButton: {
149
+ marginTop: 12,
150
+ paddingHorizontal: 16,
151
+ paddingVertical: 8,
152
+ },
153
+ retryText: {
154
+ fontSize: 15,
155
+ fontWeight: '600',
156
+ },
157
+ emptyText: {
158
+ fontSize: 16,
159
+ fontWeight: '600',
160
+ },
161
+ listContent: {
162
+ padding: 16,
163
+ },
164
+ });
@@ -0,0 +1,209 @@
1
+ import { Platform } from 'react-native';
2
+ import { getFeeddoNativeModule } from '../native/FeeddoNative';
3
+
4
+ export interface DeviceInfo {
5
+ platform: 'ios' | 'android' | 'web' | 'desktop' | 'other';
6
+ deviceModel?: string;
7
+ osVersion?: string;
8
+ appVersion?: string;
9
+ appBuildNumber?: string;
10
+ packageName?: string;
11
+ locale?: string;
12
+ countryCode?: string;
13
+ }
14
+
15
+ export class DeviceInfoHelper {
16
+ private static cachedDeviceInfo?: DeviceInfo;
17
+ private static loadPromise: Promise<DeviceInfo> | null = null;
18
+
19
+ /**
20
+ * Synchronously returns the best available device info (using cached native info if loaded).
21
+ */
22
+ public static getDeviceInfo(): DeviceInfo {
23
+ if (this.cachedDeviceInfo) {
24
+ return this.cachedDeviceInfo;
25
+ }
26
+
27
+ const fallback = this.getFallbackDeviceInfo();
28
+ this.cachedDeviceInfo = fallback;
29
+ return fallback;
30
+ }
31
+
32
+ /**
33
+ * Asynchronously collects full native device & app metadata (model, OS version, app version),
34
+ * matching `device_info_plus` + `package_info_plus` in `feeddo_flutter`.
35
+ */
36
+ public static async loadDeviceInfo(): Promise<DeviceInfo> {
37
+ if (this.cachedDeviceInfo && this.cachedDeviceInfo.appVersion) {
38
+ return this.cachedDeviceInfo;
39
+ }
40
+ if (this.loadPromise) {
41
+ return await this.loadPromise;
42
+ }
43
+
44
+ this.loadPromise = this.collectNativeDeviceInfo();
45
+ try {
46
+ const info = await this.loadPromise;
47
+ this.cachedDeviceInfo = info;
48
+ return info;
49
+ } finally {
50
+ this.loadPromise = null;
51
+ }
52
+ }
53
+
54
+ private static async collectNativeDeviceInfo(): Promise<DeviceInfo> {
55
+ const base = this.getFallbackDeviceInfo();
56
+
57
+ // 1. Built-in native iOS / Android bridge
58
+ const nativeMod = getFeeddoNativeModule();
59
+ if (nativeMod && typeof nativeMod.getDeviceInfo === 'function') {
60
+ try {
61
+ const nativeInfo = await nativeMod.getDeviceInfo();
62
+ if (nativeInfo && typeof nativeInfo === 'object') {
63
+ return {
64
+ ...base,
65
+ ...nativeInfo,
66
+ platform: (nativeInfo.platform as DeviceInfo['platform']) || base.platform,
67
+ };
68
+ }
69
+ } catch (_) { }
70
+ }
71
+
72
+ // 2. Optional `react-native-device-info` fallback (if installed without our native module)
73
+ try {
74
+ const DeviceInfoPkg = require('react-native-device-info');
75
+ const di = DeviceInfoPkg.default || DeviceInfoPkg;
76
+ if (di) {
77
+ const brand = typeof di.getBrand === 'function' ? di.getBrand() : '';
78
+ const model = typeof di.getModel === 'function' ? di.getModel() : '';
79
+ const systemName = typeof di.getSystemName === 'function' ? di.getSystemName() : '';
80
+ const systemVersion = typeof di.getSystemVersion === 'function' ? di.getSystemVersion() : '';
81
+ const appVersion = typeof di.getVersion === 'function' ? di.getVersion() : undefined;
82
+ const appBuildNumber =
83
+ typeof di.getBuildNumber === 'function' ? String(di.getBuildNumber()) : undefined;
84
+ const packageName = typeof di.getBundleId === 'function' ? di.getBundleId() : undefined;
85
+
86
+ return {
87
+ ...base,
88
+ deviceModel: [brand, model].filter(Boolean).join(' ').trim() || base.deviceModel,
89
+ osVersion:
90
+ systemName && systemVersion
91
+ ? `${systemName} ${systemVersion}`
92
+ : base.osVersion,
93
+ appVersion: appVersion || base.appVersion,
94
+ appBuildNumber: appBuildNumber || base.appBuildNumber,
95
+ packageName: packageName || base.packageName,
96
+ };
97
+ }
98
+ } catch (_) { }
99
+
100
+ // 3. Optional Expo (`expo-device` + `expo-application` + `expo-constants`) fallback
101
+ try {
102
+ let deviceModel = base.deviceModel;
103
+ let osVersion = base.osVersion;
104
+ let appVersion = base.appVersion;
105
+ let appBuildNumber = base.appBuildNumber;
106
+ let packageName = base.packageName;
107
+
108
+ try {
109
+ const ExpoDevice = require('expo-device');
110
+ if (ExpoDevice) {
111
+ const modelStr =
112
+ [ExpoDevice.manufacturer, ExpoDevice.modelName].filter(Boolean).join(' ').trim() ||
113
+ ExpoDevice.modelName;
114
+ if (modelStr) deviceModel = modelStr;
115
+ if (ExpoDevice.osName && ExpoDevice.osVersion) {
116
+ osVersion = `${ExpoDevice.osName} ${ExpoDevice.osVersion}`;
117
+ }
118
+ }
119
+ } catch (_) { }
120
+
121
+ try {
122
+ const ExpoApp = require('expo-application');
123
+ if (ExpoApp) {
124
+ if (ExpoApp.nativeApplicationVersion) appVersion = ExpoApp.nativeApplicationVersion;
125
+ if (ExpoApp.nativeBuildVersion) appBuildNumber = ExpoApp.nativeBuildVersion;
126
+ if (ExpoApp.applicationId) packageName = ExpoApp.applicationId;
127
+ }
128
+ } catch (_) { }
129
+
130
+ return {
131
+ ...base,
132
+ deviceModel,
133
+ osVersion,
134
+ appVersion,
135
+ appBuildNumber,
136
+ packageName,
137
+ };
138
+ } catch (_) { }
139
+
140
+ return base;
141
+ }
142
+
143
+ private static getFallbackDeviceInfo(): DeviceInfo {
144
+ let platform: DeviceInfo['platform'] = 'other';
145
+ let osVersion: string | undefined;
146
+
147
+ if (Platform.OS === 'ios') {
148
+ platform = 'ios';
149
+ osVersion = `iOS ${Platform.Version}`;
150
+ } else if (Platform.OS === 'android') {
151
+ platform = 'android';
152
+ osVersion = `Android ${Platform.Version}`;
153
+ } else if (Platform.OS === 'web') {
154
+ platform = 'web';
155
+ if (typeof navigator !== 'undefined') {
156
+ osVersion = navigator.userAgent;
157
+ }
158
+ } else if (Platform.OS === 'macos' || Platform.OS === 'windows') {
159
+ platform = 'desktop';
160
+ osVersion = `${Platform.OS} ${Platform.Version}`;
161
+ }
162
+
163
+ return {
164
+ platform,
165
+ osVersion,
166
+ deviceModel: Platform.select({
167
+ ios: 'iPhone',
168
+ android: 'Android',
169
+ web: 'Web Browser',
170
+ default: 'Device',
171
+ }),
172
+ locale: this.getLocale(),
173
+ countryCode: this.getCountryCode(),
174
+ };
175
+ }
176
+
177
+ public static setDeviceInfo(info: Partial<DeviceInfo>): void {
178
+ const current = this.getDeviceInfo();
179
+ this.cachedDeviceInfo = {
180
+ ...current,
181
+ ...info,
182
+ };
183
+ }
184
+
185
+ public static getLocale(): string | undefined {
186
+ if (this.cachedDeviceInfo?.locale) {
187
+ return this.cachedDeviceInfo.locale;
188
+ }
189
+ try {
190
+ if (typeof Intl !== 'undefined' && Intl.DateTimeFormat) {
191
+ return Intl.DateTimeFormat().resolvedOptions().locale;
192
+ }
193
+ } catch (_) { }
194
+ return undefined;
195
+ }
196
+
197
+ public static getCountryCode(): string | undefined {
198
+ if (this.cachedDeviceInfo?.countryCode) {
199
+ return this.cachedDeviceInfo.countryCode;
200
+ }
201
+ const locale = this.getLocale();
202
+ if (!locale) return undefined;
203
+ const parts = locale.split(/[-_]/);
204
+ if (parts.length > 1) {
205
+ return parts[1].toUpperCase();
206
+ }
207
+ return undefined;
208
+ }
209
+ }
@@ -0,0 +1,105 @@
1
+ import { Linking } from 'react-native';
2
+ import { getFeeddoNativeModule, PickedMediaFile } from '../native/FeeddoNative';
3
+
4
+ export type { PickedMediaFile };
5
+
6
+ export class MediaHelper {
7
+ private static customPicker: (() => Promise<PickedMediaFile | null>) | null = null;
8
+
9
+ public static setCustomMediaPicker(
10
+ picker: (() => Promise<PickedMediaFile | null>) | null
11
+ ): void {
12
+ this.customPicker = picker;
13
+ }
14
+
15
+ /**
16
+ * Pick an image from the device gallery using:
17
+ * 1. Custom registered picker (if provided)
18
+ * 2. Built-in native iOS (PHPickerViewController) / Android (ACTION_GET_CONTENT) module
19
+ * 3. Optional `react-native-image-picker` if installed
20
+ * 4. Optional `expo-image-picker` if installed
21
+ */
22
+ public static async pickImage(): Promise<PickedMediaFile | null> {
23
+ if (this.customPicker) {
24
+ return await this.customPicker();
25
+ }
26
+
27
+ // 1. Built-in native module
28
+ const nativeMod = getFeeddoNativeModule();
29
+ if (nativeMod && typeof nativeMod.pickImage === 'function') {
30
+ const picked = await nativeMod.pickImage();
31
+ return picked || null;
32
+ }
33
+
34
+ // 2. Optional `react-native-image-picker`
35
+ try {
36
+ const rnPicker = require('react-native-image-picker');
37
+ const launch = rnPicker.launchImageLibrary || rnPicker.default?.launchImageLibrary;
38
+ if (typeof launch === 'function') {
39
+ const result = await launch({
40
+ mediaType: 'photo',
41
+ selectionLimit: 1,
42
+ });
43
+ if (result?.didCancel || !result?.assets?.length) {
44
+ return null;
45
+ }
46
+ const asset = result.assets[0];
47
+ if (asset?.uri) {
48
+ return {
49
+ uri: asset.uri,
50
+ name: asset.fileName || 'image.jpg',
51
+ type: asset.type || 'image/jpeg',
52
+ };
53
+ }
54
+ return null;
55
+ }
56
+ } catch (_) {}
57
+
58
+ // 3. Optional `expo-image-picker`
59
+ try {
60
+ const expoPicker = require('expo-image-picker');
61
+ const launchAsync =
62
+ expoPicker.launchImageLibraryAsync || expoPicker.default?.launchImageLibraryAsync;
63
+ if (typeof launchAsync === 'function') {
64
+ const result = await launchAsync({
65
+ mediaTypes: expoPicker.MediaTypeOptions?.Images ?? 'images',
66
+ quality: 0.9,
67
+ });
68
+ if (result?.canceled || !result?.assets?.length) {
69
+ return null;
70
+ }
71
+ const asset = result.assets[0];
72
+ if (asset?.uri) {
73
+ return {
74
+ uri: asset.uri,
75
+ name: asset.fileName || 'image.jpg',
76
+ type: asset.mimeType || 'image/jpeg',
77
+ };
78
+ }
79
+ return null;
80
+ }
81
+ } catch (_) {}
82
+
83
+ throw new Error(
84
+ 'Image picker native module is unavailable. Rebuild your iOS/Android native app (pod install / gradle sync) or install react-native-image-picker.'
85
+ );
86
+ }
87
+
88
+ /**
89
+ * Opens a video attachment in a native iOS/Android video player with auth headers,
90
+ * falling back to `Linking.openURL` if native player is unavailable.
91
+ */
92
+ public static async openVideoPlayer(url: string, apiKey?: string): Promise<void> {
93
+ const nativeMod = getFeeddoNativeModule();
94
+ const headers = apiKey ? { 'x-api-key': apiKey } : undefined;
95
+
96
+ if (nativeMod && typeof nativeMod.openVideoPlayer === 'function') {
97
+ try {
98
+ await nativeMod.openVideoPlayer(url, headers);
99
+ return;
100
+ } catch (_) {}
101
+ }
102
+
103
+ await Linking.openURL(url).catch(() => {});
104
+ }
105
+ }
@@ -0,0 +1,233 @@
1
+ const TASK_TYPES = new Set([
2
+ 'task_released',
3
+ 'task_status_changed',
4
+ 'task_comment',
5
+ 'task_created',
6
+ ]);
7
+
8
+ const CONVERSATION_TYPES = new Set(['chat_message', 'new_message', 'conversation_resolved']);
9
+
10
+ const KNOWN_TYPES = new Set([...TASK_TYPES, ...CONVERSATION_TYPES]);
11
+
12
+ export function stringValue(value: any): string | undefined {
13
+ if (typeof value === 'string') {
14
+ return value.length > 0 ? value : undefined;
15
+ }
16
+ return undefined;
17
+ }
18
+
19
+ export function intValue(value: any): number | undefined {
20
+ if (typeof value === 'number' && !isNaN(value)) return Math.floor(value);
21
+ if (typeof value === 'string') {
22
+ const parsed = parseInt(value, 10);
23
+ return isNaN(parsed) ? undefined : parsed;
24
+ }
25
+ return undefined;
26
+ }
27
+
28
+ /**
29
+ * Normalizes APNs, FCM, Expo, and WebSocket notification payloads into a flat dictionary
30
+ * matching the Flutter, iOS, and Android Feeddo SDK contracts.
31
+ */
32
+ export function normalizeNotificationPayload(raw: any): Record<string, any> {
33
+ if (!raw || typeof raw !== 'object') return {};
34
+
35
+ const normalized: Record<string, any> = {};
36
+
37
+ // Handle README / wrapper shape `{ payload, data, title, message }`
38
+ const sourceObj =
39
+ raw.payload && typeof raw.payload === 'object' && !raw.type && !raw.conversationId && !raw.taskId
40
+ ? raw.payload
41
+ : raw;
42
+
43
+ // 1. Nested `data` object or JSON string
44
+ const nestedData = sourceObj.data;
45
+ if (nestedData && typeof nestedData === 'object') {
46
+ for (const [k, v] of Object.entries(nestedData)) {
47
+ if (v !== null && v !== undefined) {
48
+ normalized[k] = v;
49
+ }
50
+ }
51
+ } else if (typeof nestedData === 'string') {
52
+ try {
53
+ const parsed = JSON.parse(nestedData);
54
+ if (parsed && typeof parsed === 'object') {
55
+ for (const [k, v] of Object.entries(parsed)) {
56
+ if (v !== null && v !== undefined) {
57
+ normalized[k] = v;
58
+ }
59
+ }
60
+ }
61
+ } catch (_) {}
62
+ }
63
+
64
+ // 2. Top-level keys excluding `aps`, `data`, `notification`
65
+ for (const [k, v] of Object.entries(sourceObj)) {
66
+ if (k === 'aps' || k === 'data' || k === 'notification') continue;
67
+ if (normalized[k] === undefined && v !== null && v !== undefined) {
68
+ normalized[k] = v;
69
+ }
70
+ }
71
+
72
+ // 3. Extract `aps.alert` and `aps.badge` if present (APNs)
73
+ const aps = sourceObj.aps;
74
+ if (aps && typeof aps === 'object') {
75
+ if (aps.alert && typeof aps.alert === 'object') {
76
+ if (typeof aps.alert.title === 'string' && aps.alert.title && !normalized.title) {
77
+ normalized.title = aps.alert.title;
78
+ }
79
+ if (typeof aps.alert.body === 'string' && aps.alert.body && !normalized.body) {
80
+ normalized.body = aps.alert.body;
81
+ }
82
+ } else if (typeof aps.alert === 'string' && aps.alert && !normalized.body) {
83
+ normalized.body = aps.alert;
84
+ }
85
+ if (aps.badge !== undefined && aps.badge !== null && normalized.badge === undefined) {
86
+ normalized.badge = aps.badge;
87
+ }
88
+ }
89
+
90
+ // 4. Extract FCM `notification.title` / `notification.body` if present
91
+ const notif = raw.notification;
92
+ if (notif && typeof notif === 'object') {
93
+ if (typeof notif.title === 'string' && notif.title && !normalized.title) {
94
+ normalized.title = notif.title;
95
+ }
96
+ if (typeof notif.body === 'string' && notif.body && !normalized.body) {
97
+ normalized.body = notif.body;
98
+ }
99
+ }
100
+
101
+ // Propagate wrapper title/message if present on `raw`
102
+ if (typeof raw.title === 'string' && raw.title && !normalized.title) {
103
+ normalized.title = raw.title;
104
+ }
105
+ if (typeof raw.message === 'string' && raw.message && !normalized.body) {
106
+ normalized.body = raw.message;
107
+ }
108
+
109
+ // Normalize snake_case identifiers to camelCase aliases matching Flutter/iOS/Android payloads
110
+ const aliasPairs: Array<[string, string]> = [
111
+ ['conversation_id', 'conversationId'],
112
+ ['task_id', 'taskId'],
113
+ ['comment_id', 'commentId'],
114
+ ['message_id', 'messageId'],
115
+ ['ticket_id', 'ticketId'],
116
+ ['user_id', 'userId'],
117
+ ];
118
+ for (const [snake, camel] of aliasPairs) {
119
+ if (normalized[camel] === undefined && normalized[snake] !== undefined) {
120
+ normalized[camel] = normalized[snake];
121
+ }
122
+ }
123
+
124
+ return normalized;
125
+ }
126
+
127
+ export function isTaskNotification(type: string | undefined, payload: Record<string, any>): boolean {
128
+ if (type && TASK_TYPES.has(type)) return true;
129
+ return !type && Boolean(stringValue(payload.taskId));
130
+ }
131
+
132
+ export function isConversationNotification(
133
+ type: string | undefined,
134
+ payload: Record<string, any>
135
+ ): boolean {
136
+ if (type && CONVERSATION_TYPES.has(type)) return true;
137
+ return !type && Boolean(stringValue(payload.conversationId));
138
+ }
139
+
140
+ export function isFeeddoNotification(payload: Record<string, any> | null | undefined): boolean {
141
+ if (!payload || typeof payload !== 'object') return false;
142
+ const type = stringValue(payload.type);
143
+ if (type && KNOWN_TYPES.has(type)) return true;
144
+ if (stringValue(payload.source) === 'feeddo') return true;
145
+ return Boolean(stringValue(payload.conversationId) || stringValue(payload.taskId));
146
+ }
147
+
148
+ export function buildChatDedupKey(conversationId: string, contentOrBody?: string): string {
149
+ const raw = (contentOrBody ?? '').trim();
150
+ let stripped = raw;
151
+ const lower = raw.toLowerCase();
152
+ if (lower.startsWith('new message from ')) {
153
+ const idx = raw.indexOf(': ');
154
+ if (idx !== -1 && idx + 2 <= raw.length) {
155
+ stripped = raw.slice(idx + 2);
156
+ }
157
+ }
158
+ let normalized = stripped;
159
+ if (normalized.endsWith('...')) {
160
+ normalized = normalized.slice(0, -3);
161
+ }
162
+ normalized = normalized.trim().toLowerCase().slice(0, 40);
163
+ return `chat:${conversationId}:${normalized}`;
164
+ }
165
+
166
+ export function buildNotificationDedupKey(
167
+ payload: Record<string, any>,
168
+ body?: string
169
+ ): string | null {
170
+ const type = stringValue(payload.type);
171
+ const conversationId = stringValue(payload.conversationId);
172
+ const taskId = stringValue(payload.taskId);
173
+
174
+ if ((type === 'chat_message' || type === 'new_message') && conversationId) {
175
+ return buildChatDedupKey(conversationId, body ?? stringValue(payload.body));
176
+ }
177
+ if (type === 'conversation_resolved' && conversationId) {
178
+ return `conversation_resolved:${conversationId}`;
179
+ }
180
+ if (type && TASK_TYPES.has(type) && taskId) {
181
+ const suffix = stringValue(payload.commentId) ?? stringValue(payload.status) ?? '';
182
+ return `${type}:${taskId}:${suffix}`;
183
+ }
184
+ if (conversationId) {
185
+ return `conv:${conversationId}`;
186
+ }
187
+ if (taskId) {
188
+ return `task:${taskId}`;
189
+ }
190
+ return null;
191
+ }
192
+
193
+ export class NotificationDeduplicator {
194
+ private readonly windowMs: number;
195
+ private readonly nowMs: () => number;
196
+ private seen = new Map<string, number>();
197
+
198
+ constructor(windowMs: number = 15000, nowMs: () => number = () => Date.now()) {
199
+ this.windowMs = windowMs;
200
+ this.nowMs = nowMs;
201
+ }
202
+
203
+ public markIfNew(key: string): boolean {
204
+ const now = this.nowMs();
205
+ this.pruneExpired(now);
206
+
207
+ if (this.seen.has(key)) {
208
+ return false;
209
+ }
210
+ this.seen.set(key, now);
211
+ return true;
212
+ }
213
+
214
+ public clear(): void {
215
+ this.seen.clear();
216
+ }
217
+
218
+ private pruneExpired(now: number): void {
219
+ for (const [key, ts] of this.seen.entries()) {
220
+ if (now - ts > this.windowMs) {
221
+ this.seen.delete(key);
222
+ }
223
+ }
224
+ while (this.seen.size > 100) {
225
+ const oldestKey = this.seen.keys().next().value;
226
+ if (oldestKey !== undefined) {
227
+ this.seen.delete(oldestKey);
228
+ } else {
229
+ break;
230
+ }
231
+ }
232
+ }
233
+ }