@parlr/react-native 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (223) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +918 -0
  3. package/lib/commonjs/components/AttachmentPicker.js +292 -0
  4. package/lib/commonjs/components/AttachmentPicker.js.map +1 -0
  5. package/lib/commonjs/components/AttachmentPreview.js +200 -0
  6. package/lib/commonjs/components/AttachmentPreview.js.map +1 -0
  7. package/lib/commonjs/components/ChatBubble.js +391 -0
  8. package/lib/commonjs/components/ChatBubble.js.map +1 -0
  9. package/lib/commonjs/components/EmptyState.js +115 -0
  10. package/lib/commonjs/components/EmptyState.js.map +1 -0
  11. package/lib/commonjs/components/ParlrChat.js +745 -0
  12. package/lib/commonjs/components/ParlrChat.js.map +1 -0
  13. package/lib/commonjs/components/ParlrConversationList.js +509 -0
  14. package/lib/commonjs/components/ParlrConversationList.js.map +1 -0
  15. package/lib/commonjs/components/PreChatForm.js +263 -0
  16. package/lib/commonjs/components/PreChatForm.js.map +1 -0
  17. package/lib/commonjs/components/RichMessage.js +284 -0
  18. package/lib/commonjs/components/RichMessage.js.map +1 -0
  19. package/lib/commonjs/components/SatisfactionSurvey.js +292 -0
  20. package/lib/commonjs/components/SatisfactionSurvey.js.map +1 -0
  21. package/lib/commonjs/components/TypingIndicator.js +86 -0
  22. package/lib/commonjs/components/TypingIndicator.js.map +1 -0
  23. package/lib/commonjs/core/api.js +310 -0
  24. package/lib/commonjs/core/api.js.map +1 -0
  25. package/lib/commonjs/core/config.js +40 -0
  26. package/lib/commonjs/core/config.js.map +1 -0
  27. package/lib/commonjs/core/errors.js +73 -0
  28. package/lib/commonjs/core/errors.js.map +1 -0
  29. package/lib/commonjs/core/offlineQueue.js +89 -0
  30. package/lib/commonjs/core/offlineQueue.js.map +1 -0
  31. package/lib/commonjs/core/pushNotifications.js +21 -0
  32. package/lib/commonjs/core/pushNotifications.js.map +1 -0
  33. package/lib/commonjs/core/session.js +130 -0
  34. package/lib/commonjs/core/session.js.map +1 -0
  35. package/lib/commonjs/core/theme.js +110 -0
  36. package/lib/commonjs/core/theme.js.map +1 -0
  37. package/lib/commonjs/core/types.js +6 -0
  38. package/lib/commonjs/core/types.js.map +1 -0
  39. package/lib/commonjs/core/websocket.js +245 -0
  40. package/lib/commonjs/core/websocket.js.map +1 -0
  41. package/lib/commonjs/hooks/useChat.js +462 -0
  42. package/lib/commonjs/hooks/useChat.js.map +1 -0
  43. package/lib/commonjs/hooks/useParlr.js +44 -0
  44. package/lib/commonjs/hooks/useParlr.js.map +1 -0
  45. package/lib/commonjs/index.js +185 -0
  46. package/lib/commonjs/index.js.map +1 -0
  47. package/lib/commonjs/package.json +1 -0
  48. package/lib/commonjs/provider/ParlrContext.js +38 -0
  49. package/lib/commonjs/provider/ParlrContext.js.map +1 -0
  50. package/lib/commonjs/provider/ParlrProvider.js +256 -0
  51. package/lib/commonjs/provider/ParlrProvider.js.map +1 -0
  52. package/lib/module/components/AttachmentPicker.js +287 -0
  53. package/lib/module/components/AttachmentPicker.js.map +1 -0
  54. package/lib/module/components/AttachmentPreview.js +195 -0
  55. package/lib/module/components/AttachmentPreview.js.map +1 -0
  56. package/lib/module/components/ChatBubble.js +386 -0
  57. package/lib/module/components/ChatBubble.js.map +1 -0
  58. package/lib/module/components/EmptyState.js +110 -0
  59. package/lib/module/components/EmptyState.js.map +1 -0
  60. package/lib/module/components/ParlrChat.js +740 -0
  61. package/lib/module/components/ParlrChat.js.map +1 -0
  62. package/lib/module/components/ParlrConversationList.js +504 -0
  63. package/lib/module/components/ParlrConversationList.js.map +1 -0
  64. package/lib/module/components/PreChatForm.js +258 -0
  65. package/lib/module/components/PreChatForm.js.map +1 -0
  66. package/lib/module/components/RichMessage.js +280 -0
  67. package/lib/module/components/RichMessage.js.map +1 -0
  68. package/lib/module/components/SatisfactionSurvey.js +287 -0
  69. package/lib/module/components/SatisfactionSurvey.js.map +1 -0
  70. package/lib/module/components/TypingIndicator.js +81 -0
  71. package/lib/module/components/TypingIndicator.js.map +1 -0
  72. package/lib/module/core/api.js +305 -0
  73. package/lib/module/core/api.js.map +1 -0
  74. package/lib/module/core/config.js +36 -0
  75. package/lib/module/core/config.js.map +1 -0
  76. package/lib/module/core/errors.js +64 -0
  77. package/lib/module/core/errors.js.map +1 -0
  78. package/lib/module/core/offlineQueue.js +82 -0
  79. package/lib/module/core/offlineQueue.js.map +1 -0
  80. package/lib/module/core/pushNotifications.js +16 -0
  81. package/lib/module/core/pushNotifications.js.map +1 -0
  82. package/lib/module/core/session.js +122 -0
  83. package/lib/module/core/session.js.map +1 -0
  84. package/lib/module/core/theme.js +105 -0
  85. package/lib/module/core/theme.js.map +1 -0
  86. package/lib/module/core/types.js +4 -0
  87. package/lib/module/core/types.js.map +1 -0
  88. package/lib/module/core/websocket.js +241 -0
  89. package/lib/module/core/websocket.js.map +1 -0
  90. package/lib/module/hooks/useChat.js +458 -0
  91. package/lib/module/hooks/useChat.js.map +1 -0
  92. package/lib/module/hooks/useParlr.js +40 -0
  93. package/lib/module/hooks/useParlr.js.map +1 -0
  94. package/lib/module/index.js +58 -0
  95. package/lib/module/index.js.map +1 -0
  96. package/lib/module/package.json +1 -0
  97. package/lib/module/provider/ParlrContext.js +35 -0
  98. package/lib/module/provider/ParlrContext.js.map +1 -0
  99. package/lib/module/provider/ParlrProvider.js +251 -0
  100. package/lib/module/provider/ParlrProvider.js.map +1 -0
  101. package/lib/typescript/commonjs/components/AttachmentPicker.d.ts +23 -0
  102. package/lib/typescript/commonjs/components/AttachmentPicker.d.ts.map +1 -0
  103. package/lib/typescript/commonjs/components/AttachmentPreview.d.ts +16 -0
  104. package/lib/typescript/commonjs/components/AttachmentPreview.d.ts.map +1 -0
  105. package/lib/typescript/commonjs/components/ChatBubble.d.ts +14 -0
  106. package/lib/typescript/commonjs/components/ChatBubble.d.ts.map +1 -0
  107. package/lib/typescript/commonjs/components/EmptyState.d.ts +10 -0
  108. package/lib/typescript/commonjs/components/EmptyState.d.ts.map +1 -0
  109. package/lib/typescript/commonjs/components/ParlrChat.d.ts +34 -0
  110. package/lib/typescript/commonjs/components/ParlrChat.d.ts.map +1 -0
  111. package/lib/typescript/commonjs/components/ParlrConversationList.d.ts +17 -0
  112. package/lib/typescript/commonjs/components/ParlrConversationList.d.ts.map +1 -0
  113. package/lib/typescript/commonjs/components/PreChatForm.d.ts +20 -0
  114. package/lib/typescript/commonjs/components/PreChatForm.d.ts.map +1 -0
  115. package/lib/typescript/commonjs/components/RichMessage.d.ts +41 -0
  116. package/lib/typescript/commonjs/components/RichMessage.d.ts.map +1 -0
  117. package/lib/typescript/commonjs/components/SatisfactionSurvey.d.ts +17 -0
  118. package/lib/typescript/commonjs/components/SatisfactionSurvey.d.ts.map +1 -0
  119. package/lib/typescript/commonjs/components/TypingIndicator.d.ts +7 -0
  120. package/lib/typescript/commonjs/components/TypingIndicator.d.ts.map +1 -0
  121. package/lib/typescript/commonjs/core/api.d.ts +37 -0
  122. package/lib/typescript/commonjs/core/api.d.ts.map +1 -0
  123. package/lib/typescript/commonjs/core/config.d.ts +9 -0
  124. package/lib/typescript/commonjs/core/config.d.ts.map +1 -0
  125. package/lib/typescript/commonjs/core/errors.d.ts +35 -0
  126. package/lib/typescript/commonjs/core/errors.d.ts.map +1 -0
  127. package/lib/typescript/commonjs/core/offlineQueue.d.ts +16 -0
  128. package/lib/typescript/commonjs/core/offlineQueue.d.ts.map +1 -0
  129. package/lib/typescript/commonjs/core/pushNotifications.d.ts +6 -0
  130. package/lib/typescript/commonjs/core/pushNotifications.d.ts.map +1 -0
  131. package/lib/typescript/commonjs/core/session.d.ts +15 -0
  132. package/lib/typescript/commonjs/core/session.d.ts.map +1 -0
  133. package/lib/typescript/commonjs/core/theme.d.ts +43 -0
  134. package/lib/typescript/commonjs/core/theme.d.ts.map +1 -0
  135. package/lib/typescript/commonjs/core/types.d.ts +185 -0
  136. package/lib/typescript/commonjs/core/types.d.ts.map +1 -0
  137. package/lib/typescript/commonjs/core/websocket.d.ts +17 -0
  138. package/lib/typescript/commonjs/core/websocket.d.ts.map +1 -0
  139. package/lib/typescript/commonjs/hooks/useChat.d.ts +35 -0
  140. package/lib/typescript/commonjs/hooks/useChat.d.ts.map +1 -0
  141. package/lib/typescript/commonjs/hooks/useParlr.d.ts +11 -0
  142. package/lib/typescript/commonjs/hooks/useParlr.d.ts.map +1 -0
  143. package/lib/typescript/commonjs/index.d.ts +30 -0
  144. package/lib/typescript/commonjs/index.d.ts.map +1 -0
  145. package/lib/typescript/commonjs/package.json +1 -0
  146. package/lib/typescript/commonjs/provider/ParlrContext.d.ts +13 -0
  147. package/lib/typescript/commonjs/provider/ParlrContext.d.ts.map +1 -0
  148. package/lib/typescript/commonjs/provider/ParlrProvider.d.ts +5 -0
  149. package/lib/typescript/commonjs/provider/ParlrProvider.d.ts.map +1 -0
  150. package/lib/typescript/module/components/AttachmentPicker.d.ts +23 -0
  151. package/lib/typescript/module/components/AttachmentPicker.d.ts.map +1 -0
  152. package/lib/typescript/module/components/AttachmentPreview.d.ts +16 -0
  153. package/lib/typescript/module/components/AttachmentPreview.d.ts.map +1 -0
  154. package/lib/typescript/module/components/ChatBubble.d.ts +14 -0
  155. package/lib/typescript/module/components/ChatBubble.d.ts.map +1 -0
  156. package/lib/typescript/module/components/EmptyState.d.ts +10 -0
  157. package/lib/typescript/module/components/EmptyState.d.ts.map +1 -0
  158. package/lib/typescript/module/components/ParlrChat.d.ts +34 -0
  159. package/lib/typescript/module/components/ParlrChat.d.ts.map +1 -0
  160. package/lib/typescript/module/components/ParlrConversationList.d.ts +17 -0
  161. package/lib/typescript/module/components/ParlrConversationList.d.ts.map +1 -0
  162. package/lib/typescript/module/components/PreChatForm.d.ts +20 -0
  163. package/lib/typescript/module/components/PreChatForm.d.ts.map +1 -0
  164. package/lib/typescript/module/components/RichMessage.d.ts +41 -0
  165. package/lib/typescript/module/components/RichMessage.d.ts.map +1 -0
  166. package/lib/typescript/module/components/SatisfactionSurvey.d.ts +17 -0
  167. package/lib/typescript/module/components/SatisfactionSurvey.d.ts.map +1 -0
  168. package/lib/typescript/module/components/TypingIndicator.d.ts +7 -0
  169. package/lib/typescript/module/components/TypingIndicator.d.ts.map +1 -0
  170. package/lib/typescript/module/core/api.d.ts +37 -0
  171. package/lib/typescript/module/core/api.d.ts.map +1 -0
  172. package/lib/typescript/module/core/config.d.ts +9 -0
  173. package/lib/typescript/module/core/config.d.ts.map +1 -0
  174. package/lib/typescript/module/core/errors.d.ts +35 -0
  175. package/lib/typescript/module/core/errors.d.ts.map +1 -0
  176. package/lib/typescript/module/core/offlineQueue.d.ts +16 -0
  177. package/lib/typescript/module/core/offlineQueue.d.ts.map +1 -0
  178. package/lib/typescript/module/core/pushNotifications.d.ts +6 -0
  179. package/lib/typescript/module/core/pushNotifications.d.ts.map +1 -0
  180. package/lib/typescript/module/core/session.d.ts +15 -0
  181. package/lib/typescript/module/core/session.d.ts.map +1 -0
  182. package/lib/typescript/module/core/theme.d.ts +43 -0
  183. package/lib/typescript/module/core/theme.d.ts.map +1 -0
  184. package/lib/typescript/module/core/types.d.ts +185 -0
  185. package/lib/typescript/module/core/types.d.ts.map +1 -0
  186. package/lib/typescript/module/core/websocket.d.ts +17 -0
  187. package/lib/typescript/module/core/websocket.d.ts.map +1 -0
  188. package/lib/typescript/module/hooks/useChat.d.ts +35 -0
  189. package/lib/typescript/module/hooks/useChat.d.ts.map +1 -0
  190. package/lib/typescript/module/hooks/useParlr.d.ts +11 -0
  191. package/lib/typescript/module/hooks/useParlr.d.ts.map +1 -0
  192. package/lib/typescript/module/index.d.ts +30 -0
  193. package/lib/typescript/module/index.d.ts.map +1 -0
  194. package/lib/typescript/module/package.json +1 -0
  195. package/lib/typescript/module/provider/ParlrContext.d.ts +13 -0
  196. package/lib/typescript/module/provider/ParlrContext.d.ts.map +1 -0
  197. package/lib/typescript/module/provider/ParlrProvider.d.ts +5 -0
  198. package/lib/typescript/module/provider/ParlrProvider.d.ts.map +1 -0
  199. package/package.json +120 -0
  200. package/src/components/AttachmentPicker.tsx +310 -0
  201. package/src/components/AttachmentPreview.tsx +209 -0
  202. package/src/components/ChatBubble.tsx +424 -0
  203. package/src/components/EmptyState.tsx +118 -0
  204. package/src/components/ParlrChat.tsx +863 -0
  205. package/src/components/ParlrConversationList.tsx +559 -0
  206. package/src/components/PreChatForm.tsx +313 -0
  207. package/src/components/RichMessage.tsx +353 -0
  208. package/src/components/SatisfactionSurvey.tsx +333 -0
  209. package/src/components/TypingIndicator.tsx +89 -0
  210. package/src/core/api.ts +406 -0
  211. package/src/core/config.ts +39 -0
  212. package/src/core/errors.ts +68 -0
  213. package/src/core/offlineQueue.ts +94 -0
  214. package/src/core/pushNotifications.ts +22 -0
  215. package/src/core/session.ts +156 -0
  216. package/src/core/theme.ts +133 -0
  217. package/src/core/types.ts +237 -0
  218. package/src/core/websocket.ts +270 -0
  219. package/src/hooks/useChat.ts +534 -0
  220. package/src/hooks/useParlr.ts +43 -0
  221. package/src/index.ts +98 -0
  222. package/src/provider/ParlrContext.ts +40 -0
  223. package/src/provider/ParlrProvider.tsx +338 -0
@@ -0,0 +1,458 @@
1
+ "use strict";
2
+
3
+ // ---------------------------------------------------------------------------
4
+ // Parlr React Native SDK - useChat Hook
5
+ // ---------------------------------------------------------------------------
6
+ //
7
+ // Manages real-time chat state for a single conversation. Handles:
8
+ // - Message fetching and pagination
9
+ // - Optimistic message sending with crypto.randomUUID() idempotency keys
10
+ // - WebSocket subscriptions (new messages, typing indicators)
11
+ // - Typing notification debouncing
12
+ // - Message retry for failed sends
13
+ // ---------------------------------------------------------------------------
14
+
15
+ import { useCallback, useContext, useEffect, useRef, useState } from 'react';
16
+ import { ParlrError } from "../core/errors.js";
17
+ import { ParlrContext } from "../provider/ParlrContext.js";
18
+ const MAX_SEND_RETRIES = 3;
19
+ const RETRY_BASE_DELAY_MS = 1_000;
20
+ /** Generate a UUID v4 using crypto.randomUUID (available in Hermes/RN). */
21
+ function generateId() {
22
+ if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
23
+ return crypto.randomUUID();
24
+ }
25
+ // Fallback using crypto.getRandomValues (available in Hermes).
26
+ if (typeof crypto !== 'undefined' && typeof crypto.getRandomValues === 'function') {
27
+ const bytes = new Uint8Array(16);
28
+ crypto.getRandomValues(bytes);
29
+ // Set version (4) and variant (RFC4122).
30
+ bytes[6] = bytes[6] & 0x0f | 0x40;
31
+ bytes[8] = bytes[8] & 0x3f | 0x80;
32
+ const hex = Array.from(bytes, b => b.toString(16).padStart(2, '0')).join('');
33
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
34
+ }
35
+ // Last-resort fallback for environments without crypto.
36
+ return `${Date.now().toString(36)}-${Array.from({
37
+ length: 12
38
+ }, () => (Math.random() * 36 | 0).toString(36)).join('')}`;
39
+ }
40
+
41
+ /**
42
+ * Chat hook — manages messages and typing for one conversation.
43
+ *
44
+ * @param conversationId - Existing conversation ID, or undefined to create
45
+ * one on first `sendMessage`.
46
+ */
47
+ export function useChat(conversationId) {
48
+ const {
49
+ api,
50
+ ws,
51
+ config,
52
+ session,
53
+ refreshConversations
54
+ } = useContext(ParlrContext);
55
+ const [messages, setMessages] = useState([]);
56
+ const [conversation, setConversation] = useState(null);
57
+ const [isLoading, setIsLoading] = useState(false);
58
+ const [hasError, setHasError] = useState(false);
59
+ const [agentTyping, setAgentTyping] = useState(false);
60
+ const [page, setPage] = useState(1);
61
+ const [hasMore, setHasMore] = useState(true);
62
+
63
+ // Resolved conversation ID: uses the prop when provided, otherwise
64
+ // auto-resolved from the API by picking the most recent open conversation.
65
+ const [resolvedConvId, setResolvedConvId] = useState(conversationId);
66
+
67
+ // Mutable ref for the active conversation id (may be set lazily).
68
+ const activeConvId = useRef(resolvedConvId);
69
+ activeConvId.current = resolvedConvId ?? activeConvId.current;
70
+
71
+ // Track retry attempts per clientId.
72
+ const retryCountRef = useRef(new Map());
73
+
74
+ // Agent typing timeout — auto-clear after 5 s of silence.
75
+ const typingTimeout = useRef(null);
76
+
77
+ // Contact typing debounce — avoid spamming the server.
78
+ const lastTypingNotify = useRef(0);
79
+
80
+ // --- Keep resolved ID in sync with the prop (prop always wins) -------------
81
+
82
+ useEffect(() => {
83
+ if (conversationId) {
84
+ setResolvedConvId(conversationId);
85
+ }
86
+ }, [conversationId]);
87
+
88
+ // --- Auto-resolve: fetch the most recent open conversation from the API ---
89
+ // This runs only when no conversationId prop is provided, so returning users
90
+ // see their message history immediately without having to send a new message.
91
+
92
+ useEffect(() => {
93
+ console.log('[@parlr/react-native][useChat] auto-resolve check', {
94
+ conversationId,
95
+ resolvedConvId,
96
+ hasApi: !!api,
97
+ hasSession: !!session
98
+ });
99
+ if (conversationId || resolvedConvId || !api || !session) return;
100
+ let cancelled = false;
101
+ async function resolve() {
102
+ try {
103
+ console.log('[@parlr/react-native][useChat] fetching conversations for auto-resolve...');
104
+ const res = await api.listConversations();
105
+ console.log('[@parlr/react-native][useChat] listConversations result', {
106
+ count: res.data.length,
107
+ conversations: res.data.map(c => ({
108
+ id: c.id,
109
+ status: c.status,
110
+ lastMessageAt: c.lastMessageAt
111
+ }))
112
+ });
113
+ if (cancelled) return;
114
+ const open = res.data.filter(c => c.status !== 'closed').sort((a, b) => {
115
+ const aT = a.lastMessageAt ? new Date(a.lastMessageAt).getTime() : 0;
116
+ const bT = b.lastMessageAt ? new Date(b.lastMessageAt).getTime() : 0;
117
+ return bT - aT;
118
+ });
119
+ console.log('[@parlr/react-native][useChat] open conversations', {
120
+ count: open.length,
121
+ picked: open[0]?.id ?? 'none'
122
+ });
123
+ if (open.length > 0 && open[0]) {
124
+ setResolvedConvId(open[0].id);
125
+ }
126
+ } catch (err) {
127
+ console.warn('[@parlr/react-native][useChat] auto-resolve failed', err);
128
+ }
129
+ }
130
+ resolve();
131
+ return () => {
132
+ cancelled = true;
133
+ };
134
+ }, [conversationId, resolvedConvId, api, session]);
135
+
136
+ // --- Fetch initial messages ------------------------------------------------
137
+
138
+ useEffect(() => {
139
+ console.log('[@parlr/react-native][useChat] fetch effect', {
140
+ hasApi: !!api,
141
+ activeConvId: activeConvId.current,
142
+ hasSession: !!session,
143
+ resolvedConvId
144
+ });
145
+ if (!api || !activeConvId.current || !session) return;
146
+ let cancelled = false;
147
+ async function fetchMessages() {
148
+ setIsLoading(true);
149
+ setHasError(false);
150
+ try {
151
+ const res = await api.getMessages(activeConvId.current, 1);
152
+ if (!cancelled) {
153
+ setMessages(res.data);
154
+ setHasMore(res.meta.hasMore);
155
+ setPage(1);
156
+ }
157
+ } catch (err) {
158
+ if (config.debug) {
159
+ console.warn('[@parlr/react-native] Failed to load messages:', err);
160
+ }
161
+ config.onError?.(err instanceof ParlrError ? err : new ParlrError(err instanceof Error ? err.message : String(err)));
162
+ if (!cancelled) setHasError(true);
163
+ } finally {
164
+ if (!cancelled) setIsLoading(false);
165
+ }
166
+ }
167
+ fetchMessages();
168
+ return () => {
169
+ cancelled = true;
170
+ };
171
+ }, [api, session, config, resolvedConvId]);
172
+
173
+ // --- WebSocket subscriptions -----------------------------------------------
174
+
175
+ useEffect(() => {
176
+ if (!ws) return;
177
+ const offMessage = ws.on('new_message', payload => {
178
+ // Only append if it belongs to our active conversation.
179
+ if (payload.conversationId !== activeConvId.current) return;
180
+ const msg = {
181
+ id: payload.id,
182
+ conversationId: payload.conversationId,
183
+ senderType: payload.senderType,
184
+ senderName: payload.senderName,
185
+ senderAvatarUrl: payload.senderAvatarUrl,
186
+ content: payload.content,
187
+ createdAt: payload.createdAt,
188
+ clientId: payload.clientId,
189
+ status: 'sent'
190
+ };
191
+ setMessages(prev => {
192
+ // Deduplicate: replace optimistic message with server-confirmed one.
193
+ const withoutOptimistic = prev.filter(m => !(m.clientId && m.clientId === msg.clientId));
194
+ return [...withoutOptimistic, msg];
195
+ });
196
+
197
+ // Clear agent typing when a real message arrives.
198
+ if (msg.senderType === 'agent') {
199
+ setAgentTyping(false);
200
+ }
201
+ });
202
+ const offTypingStart = ws.on('typing_start', payload => {
203
+ if (payload.conversationId !== activeConvId.current) return;
204
+ setAgentTyping(true);
205
+
206
+ // Auto-clear after 5 s of no further typing event.
207
+ if (typingTimeout.current) clearTimeout(typingTimeout.current);
208
+ typingTimeout.current = setTimeout(() => setAgentTyping(false), 5_000);
209
+ });
210
+ const offTypingStop = ws.on('typing_stop', payload => {
211
+ if (payload.conversationId !== activeConvId.current) return;
212
+ setAgentTyping(false);
213
+ if (typingTimeout.current) clearTimeout(typingTimeout.current);
214
+ });
215
+ const offConvUpdated = ws.on('conversation_updated', payload => {
216
+ if (payload.conversationId !== activeConvId.current) return;
217
+ setConversation(prev => {
218
+ if (!prev) return prev;
219
+ return {
220
+ ...prev,
221
+ ...(payload.status !== undefined ? {
222
+ status: payload.status
223
+ } : {}),
224
+ ...(payload.assignee !== undefined ? {
225
+ assignee: payload.assignee
226
+ } : {})
227
+ };
228
+ });
229
+ });
230
+ return () => {
231
+ offMessage();
232
+ offTypingStart();
233
+ offTypingStop();
234
+ offConvUpdated();
235
+ };
236
+ }, [ws]);
237
+
238
+ // --- Polling fallback when WebSocket is not connected ----------------------
239
+
240
+ useEffect(() => {
241
+ if (!api || !session) return;
242
+ const POLL_INTERVAL = 5_000; // 5 seconds
243
+
244
+ const poll = async () => {
245
+ // Skip this tick if WebSocket is connected (real-time push handles it).
246
+ if (ws?.connected) return;
247
+ const convId = activeConvId.current;
248
+ if (!convId) return;
249
+ try {
250
+ const res = await api.getMessages(convId, 1);
251
+ setMessages(res.data);
252
+ } catch {
253
+ // Silently ignore polling errors.
254
+ }
255
+ };
256
+ const interval = setInterval(poll, POLL_INTERVAL);
257
+ return () => clearInterval(interval);
258
+ }, [api, session, ws]);
259
+
260
+ // --- Internal send logic ---------------------------------------------------
261
+
262
+ const doSend = useCallback(async (convId, content, clientId) => {
263
+ /* istanbul ignore next -- defensive guard: callers already check api */
264
+ if (!api) return;
265
+ try {
266
+ ws?.send({
267
+ type: 'send_message',
268
+ payload: {
269
+ conversationId: convId,
270
+ content,
271
+ clientId
272
+ }
273
+ });
274
+ const confirmed = await api.sendMessage(convId, content, clientId);
275
+ setMessages(prev => prev.map(m => m.clientId === clientId ? {
276
+ ...confirmed,
277
+ status: 'sent'
278
+ } : m));
279
+
280
+ // Clean up retry tracking.
281
+ retryCountRef.current.delete(clientId);
282
+ } catch (err) {
283
+ console.error('[@parlr/react-native] Failed to send message:', err);
284
+ config.onError?.(err instanceof ParlrError ? err : new ParlrError(err instanceof Error ? err.message : String(err)));
285
+ setMessages(prev => prev.map(m => m.clientId === clientId ? {
286
+ ...m,
287
+ status: 'failed'
288
+ } : m));
289
+ }
290
+ }, [api, ws, config]);
291
+
292
+ // --- Send message ----------------------------------------------------------
293
+
294
+ const sendMessage = useCallback(async content => {
295
+ if (!api) return;
296
+ const trimmed = content.trim();
297
+ if (!trimmed) return;
298
+
299
+ // 1. Create conversation if needed.
300
+ let convId = activeConvId.current;
301
+ if (!convId) {
302
+ try {
303
+ const conv = await api.createConversation(trimmed);
304
+ convId = conv.id;
305
+ activeConvId.current = convId;
306
+ setResolvedConvId(convId);
307
+ setConversation(conv);
308
+ refreshConversations();
309
+
310
+ // The server created the conversation AND the first message;
311
+ // fetch messages so we have the server-assigned IDs.
312
+ const res = await api.getMessages(convId);
313
+ setMessages(res.data);
314
+ return;
315
+ } catch (err) {
316
+ console.error('[@parlr/react-native] Failed to create conversation:', err);
317
+ config.onError?.(err instanceof ParlrError ? err : new ParlrError(err instanceof Error ? err.message : String(err)));
318
+ setHasError(true);
319
+ return;
320
+ }
321
+ }
322
+
323
+ // 2. Optimistic insert.
324
+ const clientId = generateId();
325
+ const optimistic = {
326
+ id: clientId,
327
+ conversationId: convId,
328
+ senderType: 'contact',
329
+ content: trimmed,
330
+ createdAt: new Date().toISOString(),
331
+ clientId,
332
+ status: 'sending'
333
+ };
334
+ setMessages(prev => [...prev, optimistic]);
335
+
336
+ // 3. Send via REST (for reliability) and via WS (for speed).
337
+ await doSend(convId, trimmed, clientId);
338
+ }, [api, config, refreshConversations, doSend]);
339
+
340
+ // --- Retry failed message --------------------------------------------------
341
+
342
+ const retryMessage = useCallback(async clientId => {
343
+ const msg = messages.find(m => m.clientId === clientId && m.status === 'failed');
344
+ if (!msg) return;
345
+ const currentRetries = retryCountRef.current.get(clientId) ?? 0;
346
+ if (currentRetries >= MAX_SEND_RETRIES) {
347
+ console.warn(`[@parlr/react-native] Max retries (${MAX_SEND_RETRIES}) reached for message ${clientId}`);
348
+ return;
349
+ }
350
+ retryCountRef.current.set(clientId, currentRetries + 1);
351
+
352
+ // Mark as sending again.
353
+ setMessages(prev => prev.map(m => m.clientId === clientId ? {
354
+ ...m,
355
+ status: 'sending'
356
+ } : m));
357
+
358
+ // Backoff before retry.
359
+ const backoff = RETRY_BASE_DELAY_MS * Math.pow(2, currentRetries);
360
+ await new Promise(resolve => setTimeout(resolve, backoff));
361
+ await doSend(msg.conversationId, msg.content, clientId);
362
+ }, [messages, doSend]);
363
+
364
+ // --- Typing notification ---------------------------------------------------
365
+
366
+ const notifyTyping = useCallback(isTyping => {
367
+ const convId = activeConvId.current;
368
+ if (!convId) return;
369
+
370
+ // Debounce: only send typing_start at most once every 3 s.
371
+ if (isTyping) {
372
+ const now = Date.now();
373
+ if (now - lastTypingNotify.current < 3_000) return;
374
+ lastTypingNotify.current = now;
375
+ }
376
+ ws?.send({
377
+ type: isTyping ? 'typing_start' : 'typing_stop',
378
+ payload: {
379
+ conversationId: convId
380
+ }
381
+ });
382
+
383
+ // Also notify via REST for reliability.
384
+ api?.sendTypingIndicator(convId, isTyping).catch(() => {
385
+ // Best-effort — swallow errors on typing indicators.
386
+ });
387
+ }, [api, ws]);
388
+
389
+ // --- Load more (pagination) ------------------------------------------------
390
+
391
+ const loadMore = useCallback(async () => {
392
+ const convId = activeConvId.current;
393
+ if (!api || !convId || !hasMore || isLoading) return;
394
+ const nextPage = page + 1;
395
+ try {
396
+ const res = await api.getMessages(convId, nextPage);
397
+ setMessages(prev => [...res.data, ...prev]);
398
+ setPage(nextPage);
399
+ setHasMore(res.meta.hasMore);
400
+ } catch (err) {
401
+ if (config.debug) {
402
+ console.warn('[@parlr/react-native] Failed to load more:', err);
403
+ }
404
+ }
405
+ }, [api, hasMore, isLoading, page, config.debug]);
406
+
407
+ // --- Close / Reopen --------------------------------------------------------
408
+
409
+ const closeConversation = useCallback(async () => {
410
+ const convId = activeConvId.current;
411
+ if (!api || !convId) return;
412
+ try {
413
+ const updated = await api.closeConversation(convId);
414
+ setConversation(updated);
415
+ } catch (err) {
416
+ if (config.debug) {
417
+ console.warn('[@parlr/react-native] Failed to close conversation:', err);
418
+ }
419
+ config.onError?.(err instanceof ParlrError ? err : new ParlrError(err instanceof Error ? err.message : String(err)));
420
+ }
421
+ }, [api, config]);
422
+ const reopenConversation = useCallback(async () => {
423
+ const convId = activeConvId.current;
424
+ if (!api || !convId) return;
425
+ try {
426
+ const updated = await api.reopenConversation(convId);
427
+ setConversation(updated);
428
+ } catch (err) {
429
+ if (config.debug) {
430
+ console.warn('[@parlr/react-native] Failed to reopen conversation:', err);
431
+ }
432
+ config.onError?.(err instanceof ParlrError ? err : new ParlrError(err instanceof Error ? err.message : String(err)));
433
+ }
434
+ }, [api, config]);
435
+
436
+ // --- Cleanup ---------------------------------------------------------------
437
+
438
+ useEffect(() => {
439
+ return () => {
440
+ if (typingTimeout.current) clearTimeout(typingTimeout.current);
441
+ };
442
+ }, []);
443
+ return {
444
+ messages,
445
+ isLoading,
446
+ hasError,
447
+ conversation,
448
+ agentTyping,
449
+ sendMessage,
450
+ retryMessage,
451
+ notifyTyping,
452
+ loadMore,
453
+ hasMore,
454
+ closeConversation,
455
+ reopenConversation
456
+ };
457
+ }
458
+ //# sourceMappingURL=useChat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useCallback","useContext","useEffect","useRef","useState","ParlrError","ParlrContext","MAX_SEND_RETRIES","RETRY_BASE_DELAY_MS","generateId","crypto","randomUUID","getRandomValues","bytes","Uint8Array","hex","Array","from","b","toString","padStart","join","slice","Date","now","length","Math","random","useChat","conversationId","api","ws","config","session","refreshConversations","messages","setMessages","conversation","setConversation","isLoading","setIsLoading","hasError","setHasError","agentTyping","setAgentTyping","page","setPage","hasMore","setHasMore","resolvedConvId","setResolvedConvId","activeConvId","current","retryCountRef","Map","typingTimeout","lastTypingNotify","console","log","hasApi","hasSession","cancelled","resolve","res","listConversations","count","data","conversations","map","c","id","status","lastMessageAt","open","filter","sort","a","aT","getTime","bT","picked","err","warn","fetchMessages","getMessages","meta","debug","onError","Error","message","String","offMessage","on","payload","msg","senderType","senderName","senderAvatarUrl","content","createdAt","clientId","prev","withoutOptimistic","m","offTypingStart","clearTimeout","setTimeout","offTypingStop","offConvUpdated","undefined","assignee","POLL_INTERVAL","poll","connected","convId","interval","setInterval","clearInterval","doSend","send","type","confirmed","sendMessage","delete","error","trimmed","trim","conv","createConversation","optimistic","toISOString","retryMessage","find","currentRetries","get","set","backoff","pow","Promise","notifyTyping","isTyping","sendTypingIndicator","catch","loadMore","nextPage","closeConversation","updated","reopenConversation"],"sourceRoot":"../../../src","sources":["hooks/useChat.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,WAAW,EAAEC,UAAU,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAC5E,SAASC,UAAU,QAAQ,mBAAgB;AAC3C,SAASC,YAAY,QAAQ,6BAA0B;AASvD,MAAMC,gBAAgB,GAAG,CAAC;AAC1B,MAAMC,mBAAmB,GAAG,KAAK;AA6BjC;AACA,SAASC,UAAUA,CAAA,EAAW;EAC5B,IAAI,OAAOC,MAAM,KAAK,WAAW,IAAI,OAAOA,MAAM,CAACC,UAAU,KAAK,UAAU,EAAE;IAC5E,OAAOD,MAAM,CAACC,UAAU,CAAC,CAAC;EAC5B;EACA;EACA,IAAI,OAAOD,MAAM,KAAK,WAAW,IAAI,OAAOA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MmH,kBAAkB,GAAGnJ,WAAW,CAAC,YAAY;IACjD,MAAMkH,MAAM,GAAG/D,YAAY,CAACC,OAAO;IACnC,IAAI,CAACtB,GAAG,IAAI,CAACoF,MAAM,EAAE;IAErB,IAAI;MACF,MAAMgC,OAAO,GAAG,MAAMpH,GAAG,CAACqH,kBAAkB,CAACjC,MAAM,CAAC;MACpD5E,eAAe,CAAC4G,OAAO,CAAC;IAC1B,CAAC,CAAC,OAAOjE,GAAG,EAAE;MACZ,IAAIjD,MAAM,CAACsD,KAAK,EAAE;QAChB7B,OAAO,CAACyB,IAAI,CAAC,sDAAsD,EAAED,GAAG,CAAC;MAC3E;MACAjD,MAAM,CAACuD,OAAO,GAAGN,GAAG,YAAY5E,UAAU,GAAG4E,GAAG,GAAG,IAAI5E,UAAU,CAAC4E,GAAG,YAAYO,KAAK,GAAGP,GAAG,CAACQ,OAAO,GAAGC,MAAM,CAACT,GAAG,CAAC,CAAC,CAAC;IACtH;EACF,CAAC,EAAE,CAACnD,GAAG,EAAEE,MAAM,CAAC,CAAC;;EAEjB;;EAEA9B,SAAS,CAAC,MAAM;IACd,OAAO,MAAM;MACX,IAAIqD,aAAa,CAACH,OAAO,EAAEqD,YAAY,CAAClD,aAAa,CAACH,OAAO,CAAC;IAChE,CAAC;EACH,CAAC,EAAE,EAAE,CAAC;EAEN,OAAO;IACLjB,QAAQ;IACRI,SAAS;IACTE,QAAQ;IACRJ,YAAY;IACZM,WAAW;IACX+E,WAAW;IACXS,YAAY;IACZQ,YAAY;IACZI,QAAQ;IACRhG,OAAO;IACPkG,iBAAiB;IACjBE;EACF,CAAC;AACH","ignoreList":[]}
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ // ---------------------------------------------------------------------------
4
+ // Parlr React Native SDK - useParlr Hook
5
+ // ---------------------------------------------------------------------------
6
+ //
7
+ // High-level hook for programmatic access to the SDK state and actions.
8
+ // Must be used within a <ParlrProvider>.
9
+ // ---------------------------------------------------------------------------
10
+
11
+ import { useContext } from 'react';
12
+ import { ParlrContext } from "../provider/ParlrContext.js";
13
+ /**
14
+ * Access the Parlr SDK from any component within a `<ParlrProvider>`.
15
+ *
16
+ * @example
17
+ * ```tsx
18
+ * const { isReady, identify, conversations, unreadCount } = useParlr();
19
+ * ```
20
+ */
21
+ export function useParlr() {
22
+ const ctx = useContext(ParlrContext);
23
+ if (!ctx.config.workspaceId) {
24
+ throw new Error('[@parlr/react-native] useParlr() must be used within a <ParlrProvider>. ' + 'Wrap your app root with <ParlrProvider workspaceId="ws_xxx">.');
25
+ }
26
+
27
+ // Return only the public-facing subset (omitting api/ws internals).
28
+ return {
29
+ config: ctx.config,
30
+ session: ctx.session,
31
+ isReady: ctx.isReady,
32
+ isConnected: ctx.isConnected,
33
+ conversations: ctx.conversations,
34
+ unreadCount: ctx.unreadCount,
35
+ identify: ctx.identify,
36
+ refreshConversations: ctx.refreshConversations,
37
+ theme: ctx.theme
38
+ };
39
+ }
40
+ //# sourceMappingURL=useParlr.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useContext","ParlrContext","useParlr","ctx","config","workspaceId","Error","session","isReady","isConnected","conversations","unreadCount","identify","refreshConversations","theme"],"sourceRoot":"../../../src","sources":["hooks/useParlr.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,UAAU,QAAQ,OAAO;AAClC,SAASC,YAAY,QAAQ,6BAA0B;AAGvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,QAAQA,CAAA,EAAsB;EAC5C,MAAMC,GAAG,GAAGH,UAAU,CAACC,YAAY,CAAC;EAEpC,IAAI,CAACE,GAAG,CAACC,MAAM,CAACC,WAAW,EAAE;IAC3B,MAAM,IAAIC,KAAK,CACb,0EAA0E,GACxE,+DACJ,CAAC;EACH;;EAEA;EACA,OAAO;IACLF,MAAM,EAAED,GAAG,CAACC,MAAM;IAClBG,OAAO,EAAEJ,GAAG,CAACI,OAAO;IACpBC,OAAO,EAAEL,GAAG,CAACK,OAAO;IACpBC,WAAW,EAAEN,GAAG,CAACM,WAAW;IAC5BC,aAAa,EAAEP,GAAG,CAACO,aAAa;IAChCC,WAAW,EAAER,GAAG,CAACQ,WAAW;IAC5BC,QAAQ,EAAET,GAAG,CAACS,QAAQ;IACtBC,oBAAoB,EAAEV,GAAG,CAACU,oBAAoB;IAC9CC,KAAK,EAAEX,GAAG,CAACW;EACb,CAAC;AACH","ignoreList":[]}
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+
3
+ // ---------------------------------------------------------------------------
4
+ // @parlr/react-native - Official Parlr Live Chat SDK for React Native
5
+ // ---------------------------------------------------------------------------
6
+ //
7
+ // Public API surface. Everything exported here is part of the stable contract.
8
+ //
9
+ // Usage:
10
+ //
11
+ // import { ParlrProvider, ParlrChat, useParlr, useChat } from '@parlr/react-native';
12
+ //
13
+ // // 1. Wrap your app
14
+ // <ParlrProvider workspaceId="ws_xxx">
15
+ // <App />
16
+ // </ParlrProvider>
17
+ //
18
+ // // 2. Drop the chat screen anywhere
19
+ // <ParlrChat user={{ email: 'alice@acme.com', name: 'Alice' }} onBack={goBack} />
20
+ //
21
+ // // 3. Or use hooks for programmatic access
22
+ // const { isReady, identify, unreadCount } = useParlr();
23
+ // const { messages, sendMessage, agentTyping } = useChat(conversationId);
24
+ //
25
+ // ---------------------------------------------------------------------------
26
+
27
+ // Components
28
+ export { ParlrProvider } from "./provider/ParlrProvider.js";
29
+ export { ParlrChat } from "./components/ParlrChat.js";
30
+ export { ParlrConversationList } from "./components/ParlrConversationList.js";
31
+ export { ChatBubble } from "./components/ChatBubble.js";
32
+ export { TypingIndicator } from "./components/TypingIndicator.js";
33
+ export { EmptyState } from "./components/EmptyState.js";
34
+ export { PreChatForm } from "./components/PreChatForm.js";
35
+ export { SatisfactionSurvey } from "./components/SatisfactionSurvey.js";
36
+ export { AttachmentPicker } from "./components/AttachmentPicker.js";
37
+ export { AttachmentPreview } from "./components/AttachmentPreview.js";
38
+ export { RichMessage } from "./components/RichMessage.js";
39
+
40
+ // Hooks
41
+ export { useParlr } from "./hooks/useParlr.js";
42
+ export { useChat } from "./hooks/useChat.js";
43
+
44
+ // Errors
45
+ export { ParlrError, ParlrNetworkError, ParlrAuthError, ParlrValidationError, ParlrConnectionError } from "./core/errors.js";
46
+
47
+ // Types
48
+
49
+ // Offline queue
50
+ export { queueMessage, getQueuedMessages, removeFromQueue, flushQueue } from "./core/offlineQueue.js";
51
+ // Push notifications
52
+ export { registerPushToken, unregisterPushToken } from "./core/pushNotifications.js";
53
+
54
+ // Theme
55
+ export { defaultLightTheme, defaultDarkTheme, mergeTheme } from "./core/theme.js";
56
+
57
+ // Props types (for consumers that need to type-check wrappers)
58
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["ParlrProvider","ParlrChat","ParlrConversationList","ChatBubble","TypingIndicator","EmptyState","PreChatForm","SatisfactionSurvey","AttachmentPicker","AttachmentPreview","RichMessage","useParlr","useChat","ParlrError","ParlrNetworkError","ParlrAuthError","ParlrValidationError","ParlrConnectionError","queueMessage","getQueuedMessages","removeFromQueue","flushQueue","registerPushToken","unregisterPushToken","defaultLightTheme","defaultDarkTheme","mergeTheme"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,SAASA,aAAa,QAAQ,6BAA0B;AACxD,SAASC,SAAS,QAAQ,2BAAwB;AAClD,SAASC,qBAAqB,QAAQ,uCAAoC;AAC1E,SAASC,UAAU,QAAQ,4BAAyB;AACpD,SAASC,eAAe,QAAQ,iCAA8B;AAC9D,SAASC,UAAU,QAAQ,4BAAyB;AACpD,SAASC,WAAW,QAAQ,6BAA0B;AACtD,SAASC,kBAAkB,QAAQ,oCAAiC;AACpE,SAASC,gBAAgB,QAAQ,kCAA+B;AAChE,SAASC,iBAAiB,QAAQ,mCAAgC;AAClE,SAASC,WAAW,QAAQ,6BAA0B;;AAEtD;AACA,SAASC,QAAQ,QAAQ,qBAAkB;AAC3C,SAASC,OAAO,QAAQ,oBAAiB;;AAEzC;AACA,SACEC,UAAU,EACVC,iBAAiB,EACjBC,cAAc,EACdC,oBAAoB,EACpBC,oBAAoB,QACf,kBAAe;;AAEtB;;AAkBA;AACA,SACEC,YAAY,EACZC,iBAAiB,EACjBC,eAAe,EACfC,UAAU,QACL,wBAAqB;AAG5B;AACA,SAASC,iBAAiB,EAAEC,mBAAmB,QAAQ,6BAA0B;;AAEjF;AACA,SACEC,iBAAiB,EACjBC,gBAAgB,EAChBC,UAAU,QACL,iBAAc;;AAGrB","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ // ---------------------------------------------------------------------------
4
+ // Parlr React Native SDK - React Context
5
+ // ---------------------------------------------------------------------------
6
+
7
+ import { createContext } from 'react';
8
+ import { defaultLightTheme } from "../core/theme.js";
9
+
10
+ /**
11
+ * Public context consumed by hooks (`useParlr`, `useChat`).
12
+ * Includes both user-facing state and internal plumbing (api, ws).
13
+ */
14
+
15
+ const NOOP = async () => {};
16
+ export const ParlrContext = /*#__PURE__*/createContext({
17
+ config: {
18
+ workspaceId: '',
19
+ apiBaseUrl: '',
20
+ wsUrl: '',
21
+ locale: 'fr',
22
+ debug: false
23
+ },
24
+ session: null,
25
+ isReady: false,
26
+ isConnected: false,
27
+ conversations: [],
28
+ unreadCount: 0,
29
+ identify: NOOP,
30
+ refreshConversations: NOOP,
31
+ theme: defaultLightTheme,
32
+ api: null,
33
+ ws: null
34
+ });
35
+ //# sourceMappingURL=ParlrContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createContext","defaultLightTheme","NOOP","ParlrContext","config","workspaceId","apiBaseUrl","wsUrl","locale","debug","session","isReady","isConnected","conversations","unreadCount","identify","refreshConversations","theme","api","ws"],"sourceRoot":"../../../src","sources":["provider/ParlrContext.ts"],"mappings":";;AAAA;AACA;AACA;;AAEA,SAASA,aAAa,QAAQ,OAAO;AAErC,SAASC,iBAAiB,QAAQ,kBAAe;;AAIjD;AACA;AACA;AACA;;AAMA,MAAMC,IAAI,GAAG,MAAAA,CAAA,KAAY,CAAC,CAAC;AAE3B,OAAO,MAAMC,YAAY,gBAAGH,aAAa,CAAuB;EAC9DI,MAAM,EAAE;IACNC,WAAW,EAAE,EAAE;IACfC,UAAU,EAAE,EAAE;IACdC,KAAK,EAAE,EAAE;IACTC,MAAM,EAAE,IAAI;IACZC,KAAK,EAAE;EACT,CAA0B;EAC1BC,OAAO,EAAE,IAAI;EACbC,OAAO,EAAE,KAAK;EACdC,WAAW,EAAE,KAAK;EAClBC,aAAa,EAAE,EAAE;EACjBC,WAAW,EAAE,CAAC;EACdC,QAAQ,EAAEb,IAAI;EACdc,oBAAoB,EAAEd,IAAI;EAC1Be,KAAK,EAAEhB,iBAAiB;EACxBiB,GAAG,EAAE,IAAI;EACTC,EAAE,EAAE;AACN,CAAC,CAAC","ignoreList":[]}