@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,310 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createApiClient = createApiClient;
7
+ var _axios = _interopRequireDefault(require("axios"));
8
+ var _errors = require("./errors.js");
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
+ // ---------------------------------------------------------------------------
11
+ // Parlr React Native SDK - REST API Client
12
+ // ---------------------------------------------------------------------------
13
+ //
14
+ // Wraps all widget-facing REST endpoints with automatic retry, exponential
15
+ // backoff, session-token injection, and response validation.
16
+ // ---------------------------------------------------------------------------
17
+
18
+ // ---------------------------------------------------------------------------
19
+ // Retry configuration
20
+ // ---------------------------------------------------------------------------
21
+
22
+ const MAX_RETRIES = 3;
23
+ const BASE_DELAY_MS = 500;
24
+ const RETRYABLE_STATUS = new Set([408, 429, 500, 502, 503, 504]);
25
+ function delay(ms) {
26
+ return new Promise(resolve => setTimeout(resolve, ms));
27
+ }
28
+ function isRetryable(error) {
29
+ if (!error.response) return true; // network error
30
+ return RETRYABLE_STATUS.has(error.response.status);
31
+ }
32
+
33
+ // ---------------------------------------------------------------------------
34
+ // Response validators
35
+ // ---------------------------------------------------------------------------
36
+
37
+ function validateSession(data) {
38
+ if (!data || typeof data !== 'object') {
39
+ throw new _errors.ParlrValidationError('Invalid session response: expected an object');
40
+ }
41
+ const d = data;
42
+ // Accept both "token" and "sessionToken" from the server.
43
+ const token = typeof d.token === 'string' ? d.token : d.sessionToken;
44
+ if (typeof token !== 'string' || typeof d.contactId !== 'string' || typeof d.workspaceId !== 'string' || typeof d.expiresAt !== 'string') {
45
+ throw new _errors.ParlrValidationError('Invalid session response: missing required fields (token, contactId, workspaceId, expiresAt)');
46
+ }
47
+ return {
48
+ token,
49
+ contactId: d.contactId,
50
+ workspaceId: d.workspaceId,
51
+ expiresAt: d.expiresAt
52
+ };
53
+ }
54
+ function validateMessage(data) {
55
+ if (!data || typeof data !== 'object') {
56
+ throw new _errors.ParlrValidationError('Invalid message response: expected an object');
57
+ }
58
+ const d = data;
59
+ if (typeof d.id !== 'string' || typeof d.conversationId !== 'string' || typeof d.senderType !== 'string') {
60
+ throw new _errors.ParlrValidationError('Invalid message response: missing required fields (id, conversationId, senderType)');
61
+ }
62
+ return {
63
+ id: d.id,
64
+ conversationId: d.conversationId,
65
+ content: typeof d.content === 'string' ? d.content : '',
66
+ contentType: typeof d.contentType === 'string' ? d.contentType : 'text',
67
+ senderType: d.senderType,
68
+ senderName: typeof d.senderName === 'string' ? d.senderName : undefined,
69
+ senderAvatarUrl: typeof d.senderAvatarUrl === 'string' ? d.senderAvatarUrl : undefined,
70
+ createdAt: typeof d.createdAt === 'string' ? d.createdAt : new Date().toISOString(),
71
+ clientId: typeof d.clientId === 'string' ? d.clientId : undefined,
72
+ attachments: Array.isArray(d.attachments) ? d.attachments : [],
73
+ status: 'sent'
74
+ };
75
+ }
76
+ function validateConversation(data) {
77
+ if (!data || typeof data !== 'object') {
78
+ throw new _errors.ParlrValidationError('Invalid conversation response: expected an object');
79
+ }
80
+ const d = data;
81
+ if (typeof d.id !== 'string' || typeof d.status !== 'string') {
82
+ throw new _errors.ParlrValidationError('Invalid conversation response: missing required fields (id, status)');
83
+ }
84
+ return {
85
+ id: d.id,
86
+ status: d.status,
87
+ subject: typeof d.subject === 'string' ? d.subject : null,
88
+ lastMessageAt: typeof d.lastMessageAt === 'string' ? d.lastMessageAt : null,
89
+ unreadCount: typeof d.unreadCount === 'number' ? d.unreadCount : 0,
90
+ assignee: d.assignee && typeof d.assignee === 'object' ? d.assignee : null
91
+ };
92
+ }
93
+
94
+ // ---------------------------------------------------------------------------
95
+ // Error mapper
96
+ // ---------------------------------------------------------------------------
97
+
98
+ function mapAxiosError(error) {
99
+ if (!error.response) {
100
+ return new _errors.ParlrNetworkError(error.message || 'Network request failed', undefined, {
101
+ cause: error
102
+ });
103
+ }
104
+ const status = error.response.status;
105
+ if (status === 401 || status === 403) {
106
+ return new _errors.ParlrAuthError(`Authentication failed (HTTP ${status})`, {
107
+ cause: error
108
+ });
109
+ }
110
+ return new _errors.ParlrNetworkError(`HTTP ${status}: ${error.message}`, status, {
111
+ cause: error
112
+ });
113
+ }
114
+
115
+ // ---------------------------------------------------------------------------
116
+ // Client factory
117
+ // ---------------------------------------------------------------------------
118
+
119
+ /**
120
+ * Create a configured API client bound to a resolved config and an optional
121
+ * session token accessor (so the token can be refreshed externally).
122
+ */
123
+ function createApiClient(config, getToken) {
124
+ const http = _axios.default.create({
125
+ baseURL: config.apiBaseUrl,
126
+ timeout: 15_000,
127
+ headers: {
128
+ 'Content-Type': 'application/json',
129
+ Accept: 'application/json',
130
+ 'X-Workspace-Id': config.workspaceId
131
+ }
132
+ });
133
+
134
+ // --- Inject session token and identity token on every request --------------
135
+ http.interceptors.request.use(req => {
136
+ const token = getToken();
137
+ if (token) {
138
+ req.headers.set('X-Session-Token', token);
139
+ }
140
+ if (config.identityToken) {
141
+ req.headers.set('X-Identity-Token', config.identityToken);
142
+ }
143
+ return req;
144
+ });
145
+
146
+ // --- Retry interceptor -----------------------------------------------------
147
+ http.interceptors.response.use(undefined, async error => {
148
+ const requestConfig = error.config;
149
+ if (!requestConfig) throw mapAxiosError(error);
150
+ requestConfig._retryCount = requestConfig._retryCount ?? 0;
151
+ if (requestConfig._retryCount >= MAX_RETRIES || !isRetryable(error)) {
152
+ throw mapAxiosError(error);
153
+ }
154
+ requestConfig._retryCount += 1;
155
+ const jitter = Math.random() * 200;
156
+ const backoff = BASE_DELAY_MS * Math.pow(2, requestConfig._retryCount - 1) + jitter;
157
+ if (config.debug) {
158
+ console.log(`[@parlr/react-native] Retry #${requestConfig._retryCount} after ${Math.round(backoff)}ms`);
159
+ }
160
+ await delay(backoff);
161
+ return http.request(requestConfig);
162
+ });
163
+
164
+ // --- Public API methods ----------------------------------------------------
165
+ return {
166
+ async createSession() {
167
+ const {
168
+ data
169
+ } = await http.post('/sessions', {
170
+ workspaceId: config.workspaceId
171
+ });
172
+ return validateSession(data);
173
+ },
174
+ async identify(user) {
175
+ await http.post('/identify', user);
176
+ },
177
+ async listConversations(page = 1) {
178
+ const {
179
+ data
180
+ } = await http.get('/conversations', {
181
+ params: {
182
+ page
183
+ }
184
+ });
185
+ // Handle both paginated ({ data: [...], meta: {...} }) and plain array responses.
186
+ if (Array.isArray(data)) {
187
+ const convs = data.map(validateConversation);
188
+ return {
189
+ data: convs,
190
+ meta: {
191
+ total: convs.length,
192
+ page: 1,
193
+ perPage: convs.length,
194
+ hasMore: false
195
+ }
196
+ };
197
+ }
198
+ return data;
199
+ },
200
+ async createConversation(initialMessage) {
201
+ const {
202
+ data
203
+ } = await http.post('/conversations', {
204
+ ...(initialMessage ? {
205
+ message: initialMessage
206
+ } : {})
207
+ });
208
+ return validateConversation(data);
209
+ },
210
+ async getMessages(conversationId, page = 1) {
211
+ const {
212
+ data
213
+ } = await http.get(`/conversations/${encodeURIComponent(conversationId)}/messages`, {
214
+ params: {
215
+ page
216
+ }
217
+ });
218
+ // Handle both paginated ({ data: [...], meta: {...} }) and plain array responses.
219
+ if (Array.isArray(data)) {
220
+ const messages = data.map(validateMessage);
221
+ return {
222
+ data: messages,
223
+ meta: {
224
+ total: messages.length,
225
+ page: 1,
226
+ perPage: messages.length,
227
+ hasMore: false
228
+ }
229
+ };
230
+ }
231
+ return data;
232
+ },
233
+ async sendMessage(conversationId, content, clientId) {
234
+ const {
235
+ data
236
+ } = await http.post(`/conversations/${encodeURIComponent(conversationId)}/messages`, {
237
+ content,
238
+ clientId
239
+ });
240
+ return validateMessage(data);
241
+ },
242
+ async sendTypingIndicator(conversationId, isTyping) {
243
+ await http.post(`/conversations/${encodeURIComponent(conversationId)}/typing`, {
244
+ isTyping
245
+ });
246
+ },
247
+ async closeConversation(conversationId) {
248
+ const {
249
+ data
250
+ } = await http.post(`/conversations/${encodeURIComponent(conversationId)}/close`);
251
+ return validateConversation(data);
252
+ },
253
+ async reopenConversation(conversationId) {
254
+ const {
255
+ data
256
+ } = await http.post(`/conversations/${encodeURIComponent(conversationId)}/reopen`);
257
+ return validateConversation(data);
258
+ },
259
+ async uploadAttachment(conversationId, formData) {
260
+ const {
261
+ data
262
+ } = await http.post(`/conversations/${encodeURIComponent(conversationId)}/attachments`, formData, {
263
+ headers: {
264
+ 'Content-Type': 'multipart/form-data'
265
+ }
266
+ });
267
+ return data;
268
+ },
269
+ async subscribePush(token, platform) {
270
+ await http.post('/push/subscribe', {
271
+ token,
272
+ platform
273
+ });
274
+ },
275
+ async unsubscribePush(token) {
276
+ await http.post('/push/unsubscribe', {
277
+ token
278
+ });
279
+ },
280
+ async submitRating(conversationId, score, comment) {
281
+ await http.post(`/conversations/${encodeURIComponent(conversationId)}/rating`, {
282
+ score,
283
+ comment
284
+ });
285
+ },
286
+ async searchMessages(conversationId, query) {
287
+ const {
288
+ data
289
+ } = await http.get(`/conversations/${encodeURIComponent(conversationId)}/messages/search`, {
290
+ params: {
291
+ q: query
292
+ }
293
+ });
294
+ if (Array.isArray(data)) {
295
+ const messages = data.map(validateMessage);
296
+ return {
297
+ data: messages,
298
+ meta: {
299
+ total: messages.length,
300
+ page: 1,
301
+ perPage: messages.length,
302
+ hasMore: false
303
+ }
304
+ };
305
+ }
306
+ return data;
307
+ }
308
+ };
309
+ }
310
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_axios","_interopRequireDefault","require","_errors","e","__esModule","default","MAX_RETRIES","BASE_DELAY_MS","RETRYABLE_STATUS","Set","delay","ms","Promise","resolve","setTimeout","isRetryable","error","response","has","status","validateSession","data","ParlrValidationError","d","token","sessionToken","contactId","workspaceId","expiresAt","validateMessage","id","conversationId","senderType","content","contentType","senderName","undefined","senderAvatarUrl","createdAt","Date","toISOString","clientId","attachments","Array","isArray","validateConversation","subject","lastMessageAt","unreadCount","assignee","mapAxiosError","ParlrNetworkError","message","cause","ParlrAuthError","createApiClient","config","getToken","http","axios","create","baseURL","apiBaseUrl","timeout","headers","Accept","interceptors","request","use","req","set","identityToken","requestConfig","_retryCount","jitter","Math","random","backoff","pow","debug","console","log","round","createSession","post","identify","user","listConversations","page","get","params","convs","map","meta","total","length","perPage","hasMore","createConversation","initialMessage","getMessages","encodeURIComponent","messages","sendMessage","sendTypingIndicator","isTyping","closeConversation","reopenConversation","uploadAttachment","formData","subscribePush","platform","unsubscribePush","submitRating","score","comment","searchMessages","query","q"],"sourceRoot":"../../../src","sources":["core/api.ts"],"mappings":";;;;;;AAQA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,IAAAC,OAAA,GAAAD,OAAA;AAIkB,SAAAD,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAjBlB;AACA;AACA;AACA;AACA;AACA;AACA;;AAsBA;AACA;AACA;;AAEA,MAAMG,WAAW,G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, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.resolveConfig = resolveConfig;
7
+ // ---------------------------------------------------------------------------
8
+ // Parlr React Native SDK - Configuration
9
+ // ---------------------------------------------------------------------------
10
+
11
+ const DEFAULTS = {
12
+ apiBaseUrl: 'https://api.parlr.chat/api/v1/widget',
13
+ // WebSocket disabled by default — the Java backend uses STOMP protocol,
14
+ // not the custom JSON protocol this SDK expects. Enable when the Rust
15
+ // Gateway is deployed: wsUrl: 'wss://ws.parlr.chat/ws'
16
+ wsUrl: '',
17
+ locale: 'fr',
18
+ debug: false
19
+ };
20
+
21
+ /**
22
+ * Resolve a partial user-supplied config into a fully-qualified config with
23
+ * all defaults applied.
24
+ *
25
+ * @throws {Error} if `workspaceId` is missing or empty.
26
+ */
27
+ function resolveConfig(partial) {
28
+ if (!partial.workspaceId || partial.workspaceId.trim().length === 0) {
29
+ throw new Error('[@parlr/react-native] workspaceId is required. ' + 'Pass it as a prop to <ParlrProvider workspaceId="ws_xxx" />.');
30
+ }
31
+ return {
32
+ workspaceId: partial.workspaceId.trim(),
33
+ apiBaseUrl: (partial.apiBaseUrl ?? DEFAULTS.apiBaseUrl).replace(/\/+$/, ''),
34
+ wsUrl: (partial.wsUrl ?? DEFAULTS.wsUrl).replace(/\/+$/, ''),
35
+ locale: partial.locale ?? DEFAULTS.locale,
36
+ debug: partial.debug ?? DEFAULTS.debug,
37
+ identityToken: partial.identityToken
38
+ };
39
+ }
40
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["DEFAULTS","apiBaseUrl","wsUrl","locale","debug","resolveConfig","partial","workspaceId","trim","length","Error","replace","identityToken"],"sourceRoot":"../../../src","sources":["core/config.ts"],"mappings":";;;;;;AAAA;AACA;AACA;;AAIA,MAAMA,QAAQ,GAAG;EACfC,UAAU,EAAE,sCAAsC;EAClD;EACA;EACA;EACAC,KAAK,EAAE,EAAE;EACTC,MAAM,EAAE,IAAI;EACZC,KAAK,EAAE;AACT,CAAU;;AAEV;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,aAAaA,CAACC,OAAoB,EAAkB;EAClE,IAAI,CAACA,OAAO,CAACC,WAAW,IAAID,OAAO,CAACC,WAAW,CAACC,IAAI,CAAC,CAAC,CAACC,MAAM,KAAK,CAAC,EAAE;IACnE,MAAM,IAAIC,KAAK,CACb,iDAAiD,GAC/C,8DACJ,CAAC;EACH;EAEA,OAAO;IACLH,WAAW,EAAED,OAAO,CAACC,WAAW,CAACC,IAAI,CAAC,CAAC;IACvCP,UAAU,EAAE,CAACK,OAAO,CAACL,UAAU,IAAID,QAAQ,CAACC,UAAU,EAAEU,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;IAC3ET,KAAK,EAAE,CAACI,OAAO,CAACJ,KAAK,IAAIF,QAAQ,CAACE,KAAK,EAAES,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;IAC5DR,MAAM,EAAEG,OAAO,CAACH,MAAM,IAAIH,QAAQ,CAACG,MAAM;IACzCC,KAAK,EAAEE,OAAO,CAACF,KAAK,IAAIJ,QAAQ,CAACI,KAAK;IACtCQ,aAAa,EAAEN,OAAO,CAACM;EACzB,CAAC;AACH","ignoreList":[]}
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ParlrValidationError = exports.ParlrNetworkError = exports.ParlrError = exports.ParlrConnectionError = exports.ParlrAuthError = void 0;
7
+ // ---------------------------------------------------------------------------
8
+ // Parlr React Native SDK - Error Hierarchy
9
+ // ---------------------------------------------------------------------------
10
+ //
11
+ // Typed error classes for structured error handling throughout the SDK.
12
+ // Consumers can use `instanceof` checks to differentiate error types.
13
+ // ---------------------------------------------------------------------------
14
+
15
+ /**
16
+ * Base error class for all Parlr SDK errors.
17
+ */
18
+ class ParlrError extends Error {
19
+ constructor(message, options) {
20
+ super(message, options);
21
+ this.name = 'ParlrError';
22
+ }
23
+ }
24
+
25
+ /**
26
+ * Network-level error (timeout, DNS failure, no internet).
27
+ */
28
+ exports.ParlrError = ParlrError;
29
+ class ParlrNetworkError extends ParlrError {
30
+ constructor(message, statusCode, options) {
31
+ super(message, options);
32
+ this.name = 'ParlrNetworkError';
33
+ this.statusCode = statusCode;
34
+ }
35
+ }
36
+
37
+ /**
38
+ * Authentication / session error (expired token, invalid session).
39
+ */
40
+ exports.ParlrNetworkError = ParlrNetworkError;
41
+ class ParlrAuthError extends ParlrError {
42
+ constructor(message, options) {
43
+ super(message, options);
44
+ this.name = 'ParlrAuthError';
45
+ }
46
+ }
47
+
48
+ /**
49
+ * Validation error (invalid payload from API or WebSocket).
50
+ */
51
+ exports.ParlrAuthError = ParlrAuthError;
52
+ class ParlrValidationError extends ParlrError {
53
+ constructor(message, field, options) {
54
+ super(message, options);
55
+ this.name = 'ParlrValidationError';
56
+ this.field = field;
57
+ }
58
+ }
59
+
60
+ /**
61
+ * WebSocket connection error (failed to connect, unexpected close).
62
+ */
63
+ exports.ParlrValidationError = ParlrValidationError;
64
+ class ParlrConnectionError extends ParlrError {
65
+ constructor(message, code, reason, options) {
66
+ super(message, options);
67
+ this.name = 'ParlrConnectionError';
68
+ this.code = code;
69
+ this.reason = reason;
70
+ }
71
+ }
72
+ exports.ParlrConnectionError = ParlrConnectionError;
73
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["ParlrError","Error","constructor","message","options","name","exports","ParlrNetworkError","statusCode","ParlrAuthError","ParlrValidationError","field","ParlrConnectionError","code","reason"],"sourceRoot":"../../../src","sources":["core/errors.ts"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACO,MAAMA,UAAU,SAASC,KAAK,CAAC;EACpCC,WAAWA,CAACC,OAAe,EAAEC,OAAsB,EAAE;IACnD,KAAK,CAACD,OAAO,EAAEC,OAAO,CAAC;IACvB,IAAI,CAACC,IAAI,GAAG,YAAY;EAC1B;AACF;;AAEA;AACA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2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.flushQueue = flushQueue;
7
+ exports.getQueuedMessages = getQueuedMessages;
8
+ exports.queueMessage = queueMessage;
9
+ exports.removeFromQueue = removeFromQueue;
10
+ // ---------------------------------------------------------------------------
11
+ // Parlr React Native SDK - Offline Message Queue
12
+ // ---------------------------------------------------------------------------
13
+ //
14
+ // AsyncStorage-based queue for messages sent while offline. Messages are
15
+ // persisted and flushed automatically when connectivity is restored.
16
+ // ---------------------------------------------------------------------------
17
+
18
+ const QUEUE_KEY = '@parlr/offline_queue';
19
+
20
+ // In-memory queue that mirrors persistent storage.
21
+ let memoryQueue = [];
22
+
23
+ // Lazy AsyncStorage accessor — returns null when unavailable.
24
+ function getAsyncStorage() {
25
+ try {
26
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
27
+ return require('@react-native-async-storage/async-storage').default;
28
+ } catch {
29
+ return null;
30
+ }
31
+ }
32
+ async function persist() {
33
+ try {
34
+ const storage = getAsyncStorage();
35
+ if (storage) {
36
+ await storage.setItem(QUEUE_KEY, JSON.stringify(memoryQueue));
37
+ }
38
+ } catch {
39
+ // Persistence is best-effort — the in-memory queue is always available.
40
+ }
41
+ }
42
+ async function hydrate() {
43
+ try {
44
+ const storage = getAsyncStorage();
45
+ if (storage) {
46
+ const raw = await storage.getItem(QUEUE_KEY);
47
+ if (raw) {
48
+ memoryQueue = JSON.parse(raw);
49
+ }
50
+ }
51
+ } catch {
52
+ // Start with an empty queue if hydration fails.
53
+ }
54
+ }
55
+
56
+ // Hydrate on module load (non-blocking).
57
+ hydrate();
58
+
59
+ /** Enqueue a message for later delivery. */
60
+ async function queueMessage(msg) {
61
+ memoryQueue.push(msg);
62
+ await persist();
63
+ }
64
+
65
+ /** Return all currently queued messages. */
66
+ async function getQueuedMessages() {
67
+ return [...memoryQueue];
68
+ }
69
+
70
+ /** Remove a single message from the queue by clientId. */
71
+ async function removeFromQueue(clientId) {
72
+ memoryQueue = memoryQueue.filter(m => m.clientId !== clientId);
73
+ await persist();
74
+ }
75
+
76
+ /** Attempt to send all queued messages via the API, removing successful ones. */
77
+ async function flushQueue(api) {
78
+ const snapshot = [...memoryQueue];
79
+ for (const msg of snapshot) {
80
+ try {
81
+ await api.sendMessage(msg.conversationId, msg.content, msg.clientId);
82
+ await removeFromQueue(msg.clientId);
83
+ } catch {
84
+ // Leave failed messages in the queue for the next flush attempt.
85
+ break;
86
+ }
87
+ }
88
+ }
89
+ //# sourceMappingURL=offlineQueue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["QUEUE_KEY","memoryQueue","getAsyncStorage","require","default","persist","storage","setItem","JSON","stringify","hydrate","raw","getItem","parse","queueMessage","msg","push","getQueuedMessages","removeFromQueue","clientId","filter","m","flushQueue","api","snapshot","sendMessage","conversationId","content"],"sourceRoot":"../../../src","sources":["core/offlineQueue.ts"],"mappings":";;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;;AAWA,MAAMA,SAAS,GAAG,sBAAsB;;AAExC;AACA,IAAIC,WAA4B,GAAG,EAAE;;AAErC;AACA,SAASC,eAAeA,CAAA,EAGf;EACP,IAAI;IACF;IACA,OAAOC,OAAO,CAAC,2CAA2C,CAAC,CAACC,OAAO;EACrE,CAAC,CAAC,MAAM;IACN,OAAO,IAAI;EACb;AACF;AAEA,eAAeC,OAAOA,CAAA,EAAkB;EACtC,IAAI;IACF,MAAMC,OAAO,GAAGJ,eAAe,CAAC,CAAC;IACjC,IAAII,OAAO,EAAE;MACX,MAAMA,OAAO,CAACC,OAAO,CAACP,SAAS,EAAEQ,IAAI,CAACC,SAAS,CAACR,WAAW,CAAC,CAAC;IAC/D;EACF,CAAC,CAAC,MAAM;IACN;EAAA;AAEJ;AAEA,eAAeS,OAAOA,CAAA,EAAkB;EACtC,IAAI;IACF,MAAMJ,OAAO,GAAGJ,eAAe,CAAC,CAAC;IACjC,IAAII,OAAO,EAAE;MACX,MAAMK,GAAG,GAAG,MAAML,OAAO,CAACM,OAAO,CAACZ,SAAS,CAAC;MAC5C,IAAIW,GAAG,EAAE;QACPV,WAAW,GAAGO,IAAI,CAACK,KAAK,CAACF,GAAG,CAAoB;MAClD;IACF;EACF,CAAC,CAAC,MAAM;IACN;EAAA;AAEJ;;AAEA;AACAD,OAAO,CAAC,CAAC;;AAET;AACO,eAAeI,YAAYA,CAACC,GAAkB,EAAiB;EACpEd,WAAW,CAACe,IAAI,CAACD,GAAG,CAAC;EACrB,MAAMV,OAAO,CAAC,CAAC;AACjB;;AAEA;AACO,eAAeY,iBAAiBA,CAAA,EAA6B;EAClE,OAAO,CAAC,GAAGhB,WAAW,CAAC;AACzB;;AAEA;AACO,eAAeiB,eAAeA,CAACC,QAAgB,EAAiB;EACrElB,WAAW,GAAGA,WAAW,CAACmB,MAAM,CAAEC,CAAC,IAAKA,CAAC,CAACF,QAAQ,KAAKA,QAAQ,CAAC;EAChE,MAAMd,OAAO,CAAC,CAAC;AACjB;;AAEA;AACO,eAAeiB,UAAUA,CAACC,GAAmB,EAAiB;EACnE,MAAMC,QAAQ,GAAG,CAAC,GAAGvB,WAAW,CAAC;EAEjC,KAAK,MAAMc,GAAG,IAAIS,QAAQ,EAAE;IAC1B,IAAI;MACF,MAAMD,GAAG,CAACE,WAAW,CAACV,GAAG,CAACW,cAAc,EAAEX,GAAG,CAACY,OAAO,EAAEZ,GAAG,CAACI,QAAQ,CAAC;MACpE,MAAMD,eAAe,CAACH,GAAG,CAACI,QAAQ,CAAC;IACrC,CAAC,CAAC,MAAM;MACN;MACA;IACF;EACF;AACF","ignoreList":[]}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.registerPushToken = registerPushToken;
7
+ exports.unregisterPushToken = unregisterPushToken;
8
+ // ---------------------------------------------------------------------------
9
+ // Parlr React Native SDK - Push Notification Helpers
10
+ // ---------------------------------------------------------------------------
11
+
12
+ /** Register a device push token with the Parlr backend. */
13
+ async function registerPushToken(api, token, platform) {
14
+ await api.subscribePush(token, platform);
15
+ }
16
+
17
+ /** Unregister a previously registered push token. */
18
+ async function unregisterPushToken(api, token) {
19
+ await api.unsubscribePush(token);
20
+ }
21
+ //# sourceMappingURL=pushNotifications.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["registerPushToken","api","token","platform","subscribePush","unregisterPushToken","unsubscribePush"],"sourceRoot":"../../../src","sources":["core/pushNotifications.ts"],"mappings":";;;;;;;AAAA;AACA;AACA;;AAIA;AACO,eAAeA,iBAAiBA,CACrCC,GAAmB,EACnBC,KAAa,EACbC,QAA2B,EACZ;EACf,MAAMF,GAAG,CAACG,aAAa,CAACF,KAAK,EAAEC,QAAQ,CAAC;AAC1C;;AAEA;AACO,eAAeE,mBAAmBA,CACvCJ,GAAmB,EACnBC,KAAa,EACE;EACf,MAAMD,GAAG,CAACK,eAAe,CAACJ,KAAK,CAAC;AAClC","ignoreList":[]}