@trycourier/courier-react-native 3.2.2 → 4.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 (253) hide show
  1. package/README.md +14 -3
  2. package/android/build.gradle +4 -1
  3. package/android/src/main/java/com/courierreactnative/CourierClientModule.kt +441 -0
  4. package/android/src/main/java/com/courierreactnative/CourierInboxViewManager.kt +2 -2
  5. package/android/src/main/java/com/courierreactnative/CourierReactNativeActivity.kt +4 -0
  6. package/android/src/main/java/com/courierreactnative/CourierReactNativePackage.kt +9 -3
  7. package/android/src/main/java/com/courierreactnative/CourierSharedModule.kt +312 -0
  8. package/android/src/main/java/com/courierreactnative/CourierSystemModule.kt +91 -0
  9. package/android/src/main/java/com/courierreactnative/ReactNativeModule.kt +36 -0
  10. package/android/src/main/java/com/courierreactnative/{Extensions.kt → Utils.kt} +5 -5
  11. package/courier-react-native.podspec +1 -1
  12. package/ios/CourierClientModule.swift +450 -0
  13. package/ios/CourierInboxReactNativeManager.swift +17 -9
  14. package/ios/CourierReactNativeDelegate.m +21 -35
  15. package/ios/CourierReactNativeEventEmitter.swift +25 -0
  16. package/ios/CourierReactNativeModule.m +192 -23
  17. package/ios/CourierSharedModule.swift +412 -0
  18. package/ios/CourierSystemModule.swift +136 -0
  19. package/ios/Utils.swift +103 -115
  20. package/lib/commonjs/Broadcaster.js +30 -0
  21. package/lib/commonjs/Broadcaster.js.map +1 -0
  22. package/lib/commonjs/Modules.js +25 -0
  23. package/lib/commonjs/Modules.js.map +1 -0
  24. package/lib/commonjs/client/BrandClient.js +25 -0
  25. package/lib/commonjs/client/BrandClient.js.map +1 -0
  26. package/lib/commonjs/client/ClientModule.js +21 -0
  27. package/lib/commonjs/client/ClientModule.js.map +1 -0
  28. package/lib/commonjs/client/CourierClient.js +33 -0
  29. package/lib/commonjs/client/CourierClient.js.map +1 -0
  30. package/lib/commonjs/client/InboxClient.js +116 -0
  31. package/lib/commonjs/client/InboxClient.js.map +1 -0
  32. package/lib/commonjs/client/PreferenceClient.js +73 -0
  33. package/lib/commonjs/client/PreferenceClient.js.map +1 -0
  34. package/lib/commonjs/client/TokenClient.js +36 -0
  35. package/lib/commonjs/client/TokenClient.js.map +1 -0
  36. package/lib/commonjs/client/TrackingClient.js +25 -0
  37. package/lib/commonjs/client/TrackingClient.js.map +1 -0
  38. package/lib/commonjs/index.js +418 -186
  39. package/lib/commonjs/index.js.map +1 -1
  40. package/lib/commonjs/models/Android_CourierSheet.js.map +1 -1
  41. package/lib/commonjs/models/CourierAuthenticationListener.js.map +1 -1
  42. package/lib/commonjs/models/CourierBrand.js +2 -0
  43. package/lib/commonjs/models/{CourierUserPreferencesTopic.js.map → CourierBrand.js.map} +1 -1
  44. package/lib/commonjs/models/CourierButton.js.map +1 -1
  45. package/lib/commonjs/models/CourierDevice.js +2 -0
  46. package/lib/commonjs/models/CourierDevice.js.map +1 -0
  47. package/lib/commonjs/models/CourierFont.js.map +1 -1
  48. package/lib/commonjs/models/CourierInboxListener.js +2 -2
  49. package/lib/commonjs/models/CourierInboxListener.js.map +1 -1
  50. package/lib/commonjs/models/{CourierUserPreferencesTopic.js → CourierInboxMessages.js} +1 -1
  51. package/lib/commonjs/models/CourierInboxMessages.js.map +1 -0
  52. package/lib/commonjs/models/CourierInboxTheme.js.map +1 -1
  53. package/lib/commonjs/models/CourierInfoViewStyle.js.map +1 -1
  54. package/lib/commonjs/models/CourierPaging.js.map +1 -1
  55. package/lib/commonjs/models/CourierPreferencesTheme.js.map +1 -1
  56. package/lib/commonjs/models/CourierPushListener.js +7 -3
  57. package/lib/commonjs/models/CourierPushListener.js.map +1 -1
  58. package/lib/commonjs/models/CourierPushProvider.js.map +1 -1
  59. package/lib/commonjs/models/CourierTrackingEvent.js +16 -0
  60. package/lib/commonjs/models/CourierTrackingEvent.js.map +1 -0
  61. package/lib/commonjs/models/CourierUserPreferences.js +54 -0
  62. package/lib/commonjs/models/CourierUserPreferences.js.map +1 -1
  63. package/lib/commonjs/models/InboxAction.js.map +1 -1
  64. package/lib/commonjs/models/InboxMessage.js.map +1 -1
  65. package/lib/commonjs/models/iOS_CourierCell.js.map +1 -1
  66. package/lib/commonjs/models/iOS_CourierSheet.js.map +1 -1
  67. package/lib/commonjs/utils.js +9 -17
  68. package/lib/commonjs/utils.js.map +1 -1
  69. package/lib/commonjs/views/CourierInboxView.js +3 -3
  70. package/lib/commonjs/views/CourierInboxView.js.map +1 -1
  71. package/lib/commonjs/views/CourierPreferencesView.js.map +1 -1
  72. package/lib/module/Broadcaster.js +23 -0
  73. package/lib/module/Broadcaster.js.map +1 -0
  74. package/lib/module/Modules.js +18 -0
  75. package/lib/module/Modules.js.map +1 -0
  76. package/lib/module/client/BrandClient.js +18 -0
  77. package/lib/module/client/BrandClient.js.map +1 -0
  78. package/lib/module/client/ClientModule.js +14 -0
  79. package/lib/module/client/ClientModule.js.map +1 -0
  80. package/lib/module/client/CourierClient.js +26 -0
  81. package/lib/module/client/CourierClient.js.map +1 -0
  82. package/lib/module/client/InboxClient.js +109 -0
  83. package/lib/module/client/InboxClient.js.map +1 -0
  84. package/lib/module/client/PreferenceClient.js +66 -0
  85. package/lib/module/client/PreferenceClient.js.map +1 -0
  86. package/lib/module/client/TokenClient.js +29 -0
  87. package/lib/module/client/TokenClient.js.map +1 -0
  88. package/lib/module/client/TrackingClient.js +18 -0
  89. package/lib/module/client/TrackingClient.js.map +1 -0
  90. package/lib/module/index.js +383 -185
  91. package/lib/module/index.js.map +1 -1
  92. package/lib/module/models/Android_CourierSheet.js.map +1 -1
  93. package/lib/module/models/CourierAuthenticationListener.js.map +1 -1
  94. package/lib/module/models/CourierBrand.js +2 -0
  95. package/lib/module/models/{CourierUserPreferencesTopic.js.map → CourierBrand.js.map} +1 -1
  96. package/lib/module/models/CourierButton.js.map +1 -1
  97. package/lib/module/models/CourierDevice.js +2 -0
  98. package/lib/module/models/CourierDevice.js.map +1 -0
  99. package/lib/module/models/CourierFont.js.map +1 -1
  100. package/lib/module/models/CourierInboxListener.js +1 -1
  101. package/lib/module/models/CourierInboxListener.js.map +1 -1
  102. package/lib/module/models/CourierInboxMessages.js +2 -0
  103. package/lib/module/models/CourierInboxMessages.js.map +1 -0
  104. package/lib/module/models/CourierInboxTheme.js.map +1 -1
  105. package/lib/module/models/CourierInfoViewStyle.js.map +1 -1
  106. package/lib/module/models/CourierPaging.js.map +1 -1
  107. package/lib/module/models/CourierPreferencesTheme.js.map +1 -1
  108. package/lib/module/models/CourierPushListener.js +7 -3
  109. package/lib/module/models/CourierPushListener.js.map +1 -1
  110. package/lib/module/models/CourierPushProvider.js.map +1 -1
  111. package/lib/module/models/CourierTrackingEvent.js +9 -0
  112. package/lib/module/models/CourierTrackingEvent.js.map +1 -0
  113. package/lib/module/models/CourierUserPreferences.js +53 -1
  114. package/lib/module/models/CourierUserPreferences.js.map +1 -1
  115. package/lib/module/models/InboxAction.js.map +1 -1
  116. package/lib/module/models/InboxMessage.js.map +1 -1
  117. package/lib/module/models/iOS_CourierCell.js.map +1 -1
  118. package/lib/module/models/iOS_CourierSheet.js.map +1 -1
  119. package/lib/module/utils.js +7 -16
  120. package/lib/module/utils.js.map +1 -1
  121. package/lib/module/views/CourierInboxView.js +3 -3
  122. package/lib/module/views/CourierInboxView.js.map +1 -1
  123. package/lib/module/views/CourierPreferencesView.js.map +1 -1
  124. package/lib/typescript/src/Broadcaster.d.ts +14 -0
  125. package/lib/typescript/src/Broadcaster.d.ts.map +1 -0
  126. package/lib/typescript/src/Modules.d.ts +8 -0
  127. package/lib/typescript/src/Modules.d.ts.map +1 -0
  128. package/lib/typescript/src/client/BrandClient.d.ts +15 -0
  129. package/lib/typescript/src/client/BrandClient.d.ts.map +1 -0
  130. package/lib/typescript/src/client/ClientModule.d.ts +8 -0
  131. package/lib/typescript/src/client/ClientModule.d.ts.map +1 -0
  132. package/lib/typescript/src/client/CourierClient.d.ts +31 -0
  133. package/lib/typescript/src/client/CourierClient.d.ts.map +1 -0
  134. package/lib/typescript/src/client/InboxClient.d.ts +94 -0
  135. package/lib/typescript/src/client/InboxClient.d.ts.map +1 -0
  136. package/lib/typescript/src/client/PreferenceClient.d.ts +39 -0
  137. package/lib/typescript/src/client/PreferenceClient.d.ts.map +1 -0
  138. package/lib/typescript/src/client/TokenClient.d.ts +28 -0
  139. package/lib/typescript/src/client/TokenClient.d.ts.map +1 -0
  140. package/lib/typescript/src/client/TrackingClient.d.ts +17 -0
  141. package/lib/typescript/src/client/TrackingClient.d.ts.map +1 -0
  142. package/lib/typescript/src/index.d.ts +300 -0
  143. package/lib/typescript/src/index.d.ts.map +1 -0
  144. package/lib/typescript/src/models/Android_CourierSheet.d.ts.map +1 -0
  145. package/lib/typescript/src/models/CourierAuthenticationListener.d.ts.map +1 -0
  146. package/lib/typescript/src/models/CourierBrand.d.ts +20 -0
  147. package/lib/typescript/src/models/CourierBrand.d.ts.map +1 -0
  148. package/lib/typescript/src/models/CourierButton.d.ts.map +1 -0
  149. package/lib/typescript/src/models/CourierDevice.d.ts +9 -0
  150. package/lib/typescript/src/models/CourierDevice.d.ts.map +1 -0
  151. package/lib/typescript/src/models/CourierFont.d.ts.map +1 -0
  152. package/lib/typescript/src/models/CourierInboxListener.d.ts.map +1 -0
  153. package/lib/typescript/src/models/CourierInboxMessages.d.ts +23 -0
  154. package/lib/typescript/src/models/CourierInboxMessages.d.ts.map +1 -0
  155. package/lib/typescript/src/models/CourierInboxTheme.d.ts.map +1 -0
  156. package/lib/typescript/src/models/CourierInfoViewStyle.d.ts.map +1 -0
  157. package/lib/typescript/src/models/CourierPaging.d.ts.map +1 -0
  158. package/lib/typescript/src/models/CourierPreferencesTheme.d.ts.map +1 -0
  159. package/lib/typescript/src/models/CourierPushListener.d.ts +8 -0
  160. package/lib/typescript/src/models/CourierPushListener.d.ts.map +1 -0
  161. package/lib/typescript/src/models/CourierPushProvider.d.ts.map +1 -0
  162. package/lib/typescript/src/models/CourierTrackingEvent.d.ts +8 -0
  163. package/lib/typescript/src/models/CourierTrackingEvent.d.ts.map +1 -0
  164. package/lib/typescript/src/models/CourierUserPreferences.d.ts +35 -0
  165. package/lib/typescript/src/models/CourierUserPreferences.d.ts.map +1 -0
  166. package/lib/typescript/src/models/InboxAction.d.ts.map +1 -0
  167. package/lib/typescript/src/models/InboxMessage.d.ts.map +1 -0
  168. package/lib/typescript/src/models/iOS_CourierCell.d.ts.map +1 -0
  169. package/lib/typescript/src/models/iOS_CourierSheet.d.ts.map +1 -0
  170. package/lib/typescript/src/utils.d.ts +14 -0
  171. package/lib/typescript/src/utils.d.ts.map +1 -0
  172. package/lib/typescript/src/views/CourierInboxView.d.ts.map +1 -0
  173. package/lib/typescript/src/views/CourierPreferencesView.d.ts.map +1 -0
  174. package/package.json +3 -3
  175. package/src/Broadcaster.tsx +32 -0
  176. package/src/Modules.tsx +28 -0
  177. package/src/client/BrandClient.tsx +23 -0
  178. package/src/client/ClientModule.tsx +21 -0
  179. package/src/client/CourierClient.tsx +49 -0
  180. package/src/client/InboxClient.tsx +114 -0
  181. package/src/client/PreferenceClient.tsx +77 -0
  182. package/src/client/TokenClient.tsx +34 -0
  183. package/src/client/TrackingClient.tsx +23 -0
  184. package/src/index.tsx +398 -205
  185. package/src/models/CourierBrand.tsx +24 -0
  186. package/src/models/CourierDevice.tsx +8 -0
  187. package/src/models/CourierInboxListener.tsx +1 -1
  188. package/src/models/CourierInboxMessages.tsx +28 -0
  189. package/src/models/CourierPushListener.tsx +11 -6
  190. package/src/models/CourierTrackingEvent.tsx +7 -0
  191. package/src/models/CourierUserPreferences.tsx +70 -3
  192. package/src/utils.tsx +7 -23
  193. package/src/views/CourierInboxView.tsx +3 -3
  194. package/android/src/main/java/com/courierreactnative/CourierReactNativeModule.kt +0 -393
  195. package/ios/CourierReactNativeModule.swift +0 -524
  196. package/lib/commonjs/models/CourierUserPreferencesChannel.js +0 -17
  197. package/lib/commonjs/models/CourierUserPreferencesChannel.js.map +0 -1
  198. package/lib/commonjs/models/CourierUserPreferencesStatus.js +0 -15
  199. package/lib/commonjs/models/CourierUserPreferencesStatus.js.map +0 -1
  200. package/lib/module/models/CourierUserPreferencesChannel.js +0 -10
  201. package/lib/module/models/CourierUserPreferencesChannel.js.map +0 -1
  202. package/lib/module/models/CourierUserPreferencesStatus.js +0 -8
  203. package/lib/module/models/CourierUserPreferencesStatus.js.map +0 -1
  204. package/lib/module/models/CourierUserPreferencesTopic.js +0 -2
  205. package/lib/typescript/index.d.ts +0 -199
  206. package/lib/typescript/index.d.ts.map +0 -1
  207. package/lib/typescript/models/Android_CourierSheet.d.ts.map +0 -1
  208. package/lib/typescript/models/CourierAuthenticationListener.d.ts.map +0 -1
  209. package/lib/typescript/models/CourierButton.d.ts.map +0 -1
  210. package/lib/typescript/models/CourierFont.d.ts.map +0 -1
  211. package/lib/typescript/models/CourierInboxListener.d.ts.map +0 -1
  212. package/lib/typescript/models/CourierInboxTheme.d.ts.map +0 -1
  213. package/lib/typescript/models/CourierInfoViewStyle.d.ts.map +0 -1
  214. package/lib/typescript/models/CourierPaging.d.ts.map +0 -1
  215. package/lib/typescript/models/CourierPreferencesTheme.d.ts.map +0 -1
  216. package/lib/typescript/models/CourierPushListener.d.ts +0 -7
  217. package/lib/typescript/models/CourierPushListener.d.ts.map +0 -1
  218. package/lib/typescript/models/CourierPushProvider.d.ts.map +0 -1
  219. package/lib/typescript/models/CourierUserPreferences.d.ts +0 -7
  220. package/lib/typescript/models/CourierUserPreferences.d.ts.map +0 -1
  221. package/lib/typescript/models/CourierUserPreferencesChannel.d.ts +0 -9
  222. package/lib/typescript/models/CourierUserPreferencesChannel.d.ts.map +0 -1
  223. package/lib/typescript/models/CourierUserPreferencesStatus.d.ts +0 -7
  224. package/lib/typescript/models/CourierUserPreferencesStatus.d.ts.map +0 -1
  225. package/lib/typescript/models/CourierUserPreferencesTopic.d.ts +0 -13
  226. package/lib/typescript/models/CourierUserPreferencesTopic.d.ts.map +0 -1
  227. package/lib/typescript/models/InboxAction.d.ts.map +0 -1
  228. package/lib/typescript/models/InboxMessage.d.ts.map +0 -1
  229. package/lib/typescript/models/iOS_CourierCell.d.ts.map +0 -1
  230. package/lib/typescript/models/iOS_CourierSheet.d.ts.map +0 -1
  231. package/lib/typescript/utils.d.ts +0 -21
  232. package/lib/typescript/utils.d.ts.map +0 -1
  233. package/lib/typescript/views/CourierInboxView.d.ts.map +0 -1
  234. package/lib/typescript/views/CourierPreferencesView.d.ts.map +0 -1
  235. package/src/models/CourierUserPreferencesChannel.tsx +0 -8
  236. package/src/models/CourierUserPreferencesStatus.tsx +0 -6
  237. package/src/models/CourierUserPreferencesTopic.tsx +0 -13
  238. /package/lib/typescript/{models → src/models}/Android_CourierSheet.d.ts +0 -0
  239. /package/lib/typescript/{models → src/models}/CourierAuthenticationListener.d.ts +0 -0
  240. /package/lib/typescript/{models → src/models}/CourierButton.d.ts +0 -0
  241. /package/lib/typescript/{models → src/models}/CourierFont.d.ts +0 -0
  242. /package/lib/typescript/{models → src/models}/CourierInboxListener.d.ts +0 -0
  243. /package/lib/typescript/{models → src/models}/CourierInboxTheme.d.ts +0 -0
  244. /package/lib/typescript/{models → src/models}/CourierInfoViewStyle.d.ts +0 -0
  245. /package/lib/typescript/{models → src/models}/CourierPaging.d.ts +0 -0
  246. /package/lib/typescript/{models → src/models}/CourierPreferencesTheme.d.ts +0 -0
  247. /package/lib/typescript/{models → src/models}/CourierPushProvider.d.ts +0 -0
  248. /package/lib/typescript/{models → src/models}/InboxAction.d.ts +0 -0
  249. /package/lib/typescript/{models → src/models}/InboxMessage.d.ts +0 -0
  250. /package/lib/typescript/{models → src/models}/iOS_CourierCell.d.ts +0 -0
  251. /package/lib/typescript/{models → src/models}/iOS_CourierSheet.d.ts +0 -0
  252. /package/lib/typescript/{views → src/views}/CourierInboxView.d.ts +0 -0
  253. /package/lib/typescript/{views → src/views}/CourierPreferencesView.d.ts +0 -0
package/src/index.tsx CHANGED
@@ -1,8 +1,6 @@
1
1
  import {
2
- EmitterSubscription,
3
2
  Platform,
4
- NativeModules,
5
- NativeEventEmitter,
3
+ EmitterSubscription,
6
4
  } from 'react-native';
7
5
 
8
6
  // Imports
@@ -10,21 +8,27 @@ import { CourierInboxListener } from './models/CourierInboxListener';
10
8
  import { CourierPushListener } from './models/CourierPushListener';
11
9
  import { CourierAuthenticationListener } from './models/CourierAuthenticationListener';
12
10
  import { InboxMessage } from './models/InboxMessage';
13
- import { CourierUserPreferences } from './models/CourierUserPreferences';
14
- import { CourierUserPreferencesTopic } from './models/CourierUserPreferencesTopic';
15
- import { CourierUserPreferencesChannel } from './models/CourierUserPreferencesChannel';
16
- import { CourierUserPreferencesStatus } from './models/CourierUserPreferencesStatus';
17
11
  import { CourierPushProvider } from './models/CourierPushProvider';
12
+ import { Modules } from './Modules';
13
+ import Broadcaster from './Broadcaster';
14
+ import { CourierClient } from './client/CourierClient';
18
15
  import { Events, Utils } from './utils';
19
16
 
17
+ export { CourierClient } from './client/CourierClient';
18
+ export { BrandClient } from './client/BrandClient';
19
+ export { CourierBrandResponse } from './models/CourierBrand';
20
+ export { CourierDevice } from './models/CourierDevice';
21
+
20
22
  // Exports
21
23
  export { CourierInboxView } from './views/CourierInboxView';
22
24
  export { CourierPreferencesView } from './views/CourierPreferencesView';
23
25
  export { CourierInboxListener } from './models/CourierInboxListener';
24
26
  export { CourierPushListener } from './models/CourierPushListener';
27
+ export { CourierUserPreferencesTopic } from './models/CourierUserPreferences';
25
28
  export { CourierAuthenticationListener } from './models/CourierAuthenticationListener';
26
- export { CourierUserPreferencesChannel } from './models/CourierUserPreferencesChannel';
27
- export { CourierUserPreferencesStatus } from './models/CourierUserPreferencesStatus';
29
+ export { CourierUserPreferencesChannel } from './models/CourierUserPreferences';
30
+ export { CourierUserPreferencesStatus } from './models/CourierUserPreferences';
31
+ export { CourierTrackingEvent } from './models/CourierTrackingEvent';
28
32
  export { CourierPushProvider } from './models/CourierPushProvider';
29
33
  export { CourierFont } from './models/CourierFont';
30
34
  export { CourierButton } from './models/CourierButton';
@@ -35,42 +39,32 @@ export { CourierInboxButtonStyle, CourierInboxTextStyle, CourierInboxUnreadIndic
35
39
  export { CourierPreferencesTheme, CourierPreferencesMode, CourierPreferencesChannel } from './models/CourierPreferencesTheme';
36
40
  export type iOSForegroundPresentationOptions = 'sound' | 'badge' | 'list' | 'banner';
37
41
 
38
- const LINKING_ERROR =
39
- `The package '@trycourier/courier-react-native' doesn't seem to be linked. Make sure: \n\n` +
40
- Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
41
- '- You rebuilt the app after installing the package\n' +
42
- '- You are not using Expo Go\n';
43
-
44
- const CourierReactNativeModules = NativeModules.CourierReactNativeModule
45
- ? NativeModules.CourierReactNativeModule
46
- : new Proxy(
47
- {},
48
- {
49
- get() {
50
- throw new Error(LINKING_ERROR);
51
- },
52
- }
53
- );
54
-
55
- const CourierEventEmitter = new NativeEventEmitter(
56
- NativeModules.CourierReactNativeModule
57
- );
58
-
59
42
  class Courier {
60
43
 
44
+ // Singleton
61
45
  private static _sharedInstance: Courier;
62
- private _isDebugging = false;
63
- private debugListener: EmitterSubscription | undefined;
64
46
 
65
- private authListeners: Map<string, CourierAuthenticationListener> = new Map<string, CourierAuthenticationListener>();
66
- private inboxListeners: Map<string, CourierInboxListener> = new Map<string, CourierInboxListener>();
47
+ // Listeners
48
+ private authenticationListeners = new Map<string, CourierAuthenticationListener>();
49
+ private inboxListeners = new Map<string, CourierInboxListener>();
50
+ private pushListeners = new Map<string, CourierPushListener>();
51
+
52
+ // Broadcasting
53
+ private systemBroadcaster = new Broadcaster(Modules.System);
54
+ private sharedBroadcaster = new Broadcaster(Modules.Shared);
55
+ private pushNotificationClickedEmitter: EmitterSubscription | undefined;
56
+ private pushNotificationDeliveredEmitter: EmitterSubscription | undefined;
67
57
 
68
58
  public constructor() {
69
59
 
70
60
  // Sets the initial SDK values
71
- // Defaults to React Native level debugging
72
- // and will show all foreground notification styles in iOS
73
- this.setDefaults();
61
+ // will show all foreground notification styles in iOS
62
+ Courier.setIOSForegroundPresentationOptions({
63
+ options: ['sound', 'badge', 'list', 'banner']
64
+ });
65
+
66
+ // Attach the push notification listeners
67
+ this.attachPushNotificationListeners();
74
68
 
75
69
  }
76
70
 
@@ -85,241 +79,435 @@ class Courier {
85
79
 
86
80
  }
87
81
 
88
- private async setDefaults() {
89
- this.setIsDebugging(__DEV__);
90
- this.iOSForegroundPresentationOptions({ options: ['sound', 'badge', 'list', 'banner'] });
82
+ // Debugging
83
+
84
+ private isDebugging = __DEV__;
85
+
86
+ // Show a log to the console
87
+ static log(message: string): void {
88
+ if (Courier.shared.isDebugging) {
89
+ console.log(message);
90
+ }
91
+ }
92
+
93
+ // System (Static)
94
+
95
+ private attachPushNotificationListeners() {
96
+
97
+ // Remove existing listeners
98
+ // Only allows one subscription to be active
99
+ this.pushNotificationClickedEmitter?.remove();
100
+ this.pushNotificationDeliveredEmitter?.remove();
101
+
102
+ // When a push notification is clicked
103
+ this.pushNotificationClickedEmitter = this.systemBroadcaster.addListener(Events.Push.CLICKED, (event) => {
104
+ try {
105
+ const message = JSON.parse(event);
106
+ this.pushListeners.forEach(listener => {
107
+ if (listener.onPushNotificationClicked) {
108
+ listener.onPushNotificationClicked(message);
109
+ }
110
+ });
111
+ } catch (error) {
112
+ Courier.log(`Error parsing push notification clicked event: ${error}`);
113
+ }
114
+ });
115
+
116
+ // When a push notification is delivered
117
+ this.pushNotificationDeliveredEmitter = this.systemBroadcaster.addListener(Events.Push.DELIVERED, (event) => {
118
+ try {
119
+ const message = JSON.parse(event);
120
+ this.pushListeners.forEach(listener => {
121
+ if (listener.onPushNotificationDelivered) {
122
+ listener.onPushNotificationDelivered(message);
123
+ }
124
+ });
125
+ } catch (error) {
126
+ Courier.log(`Error parsing push notification delivered event: ${error}`);
127
+ }
128
+ });
91
129
  }
92
130
 
93
131
  /**
94
- * Tells native Courier SDKs to show or hide logs.
95
- * Defaults to the React __DEV__ mode
132
+ * Sets the iOS foreground presentation options for push notifications.
133
+ * This method only works on iOS devices.
134
+ * @param props An object containing an array of iOSForegroundPresentationOptions.
135
+ * @returns A string indicating the result of the operation. Returns 'unsupported' on non-iOS platforms.
96
136
  */
97
- public setIsDebugging(isDebugging: boolean): boolean {
98
-
99
- // Remove the existing listener if needed
100
- this.debugListener?.remove();
137
+ public static setIOSForegroundPresentationOptions(props: { options: iOSForegroundPresentationOptions[] }): string {
101
138
 
102
- // Set a new listener
103
- // listener needs to be registered first to catch the event
104
- if (isDebugging) {
105
- this.debugListener = CourierEventEmitter.addListener(Events.Log.DEBUG_LOG, event => {
106
- console.log('\x1b[36m%s\x1b[0m', 'COURIER', event);
107
- });
108
- }
139
+ // Only works on iOS
140
+ if (Platform.OS !== 'ios') return 'unsupported';
109
141
 
110
- CourierReactNativeModules.setDebugMode(isDebugging);
142
+ const normalizedParams = Array.from(new Set(props.options));
143
+ return Modules.System.setIOSForegroundPresentationOptions({
144
+ options: normalizedParams,
145
+ });
111
146
 
112
- this._isDebugging = isDebugging
147
+ }
113
148
 
114
- return this._isDebugging;
149
+ /**
150
+ * Retrieves the current notification permission status.
151
+ * @returns A Promise that resolves to a string representing the current notification permission status.
152
+ */
153
+ public static async getNotificationPermissionStatus(): Promise<string> {
154
+ return await Modules.System.getNotificationPermissionStatus();
155
+ }
115
156
 
157
+ /**
158
+ * Requests permission to send push notifications to the user.
159
+ * @returns A Promise that resolves to a string indicating the result of the permission request.
160
+ */
161
+ public static async requestNotificationPermission(): Promise<string> {
162
+ return await Modules.System.requestNotificationPermission();
116
163
  }
117
164
 
118
165
  /**
119
- * Returns the status of debugging
166
+ * Opens the settings page for the current app.
167
+ * This can be used to direct users to enable notifications if they've previously denied permission.
120
168
  */
121
- get isDebugging(): boolean {
122
- return this._isDebugging;
169
+ public static openSettingsForApp() {
170
+ Modules.System.openSettingsForApp();
123
171
  }
124
172
 
173
+ // Client
174
+
125
175
  /**
126
- * Sets the notification presentation options for iOS
176
+ * Gets the current CourierClient instance.
177
+ * @returns {CourierClient | undefined} The current CourierClient instance, or undefined if not initialized.
127
178
  */
128
- public iOSForegroundPresentationOptions(props: { options: iOSForegroundPresentationOptions[] }): string {
179
+ public get client(): CourierClient | undefined {
129
180
 
130
- // Only works on iOS
131
- if (Platform.OS !== 'ios') return 'unsupported';
181
+ const client = Modules.Shared.getClient() ?? undefined;
132
182
 
133
- const normalizedParams = Array.from(new Set(props.options));
134
- return CourierReactNativeModules.iOSForegroundPresentationOptions({
135
- options: normalizedParams,
183
+ if (!client) {
184
+ return undefined;
185
+ }
186
+
187
+ const clientObj = JSON.parse(client);
188
+
189
+ return new CourierClient({
190
+ userId: clientObj.userId,
191
+ showLogs: clientObj.showLogs,
192
+ jwt: clientObj.jwt,
193
+ clientKey: clientObj.clientKey,
194
+ connectionId: clientObj.connectionId,
195
+ tenantId: clientObj.tenantId,
136
196
  });
137
197
 
138
198
  }
139
199
 
200
+ // Authentication
201
+
140
202
  /**
141
- * Gets a token for key
203
+ * Gets the current user ID.
204
+ * @returns {string | undefined} The current user ID, or undefined if not set.
142
205
  */
143
- public getToken(props: { key: string }): Promise<string | undefined> {
144
- return CourierReactNativeModules.getToken(props.key);
206
+ public get userId(): string | undefined {
207
+ return Modules.Shared.getUserId() ?? undefined;
145
208
  }
146
209
 
147
- public getTokenForProvider(props: { provider: CourierPushProvider }): Promise<string | undefined> {
148
- return CourierReactNativeModules.getToken(props.provider);
210
+ /**
211
+ * Gets the current tenant ID.
212
+ * @returns {string | undefined} The current tenant ID, or undefined if not set.
213
+ */
214
+ public get tenantId(): string | undefined {
215
+ return Modules.Shared.getTenantId() ?? undefined;
149
216
  }
150
217
 
151
218
  /**
152
- * Sets the fcm token to be used by Courier
219
+ * Checks if a user is currently signed in.
220
+ * @returns {boolean} True if a user is signed in, false otherwise.
153
221
  */
154
- public setToken(props: { key: string, token: string }): Promise<void> {
155
- return CourierReactNativeModules.setToken(props.key, props.token);
222
+ public get isUserSignedIn(): boolean {
223
+ const isSignedIn: string = Modules.Shared.getIsUserSignedIn() ?? 'false';
224
+ return isSignedIn.toLowerCase() === 'true';
156
225
  }
157
226
 
158
- public setTokenForProvider(props: { provider: CourierPushProvider, token: string }): Promise<void> {
159
- return CourierReactNativeModules.setToken(props.provider, props.token);
227
+ /**
228
+ * Signs out the current user.
229
+ * @returns {Promise<void>} A promise that resolves when the sign out process is complete.
230
+ */
231
+ public async signOut(): Promise<void> {
232
+ return await Modules.Shared.signOut();
160
233
  }
161
234
 
162
235
  /**
163
- * Returns the notification permission status
164
- * Only supported on iOS
236
+ * Signs in a user with the provided credentials.
237
+ * @param {Object} props - The sign-in properties.
238
+ * @param {string} props.accessToken - The access token for authentication.
239
+ * @param {string} [props.clientKey] - The client key (optional).
240
+ * @param {string} props.userId - The user ID.
241
+ * @param {string} [props.tenantId] - The tenant ID (optional).
242
+ * @param {boolean} [props.showLogs] - Whether to show debug logs (defaults to __DEV__).
243
+ * @returns {Promise<void>} A promise that resolves when the sign-in process is complete.
165
244
  */
166
- public getNotificationPermissionStatus(): Promise<string> {
167
- return CourierReactNativeModules.getNotificationPermissionStatus();
245
+ public async signIn(props: { accessToken: string, clientKey?: string, userId: string, tenantId?: string, showLogs?: boolean }): Promise<void> {
246
+ this.isDebugging = props.showLogs ?? __DEV__;
247
+ return await Modules.Shared.signIn(
248
+ props.accessToken,
249
+ props.clientKey ?? null,
250
+ props.userId,
251
+ props.tenantId ?? null,
252
+ this.isDebugging
253
+ );
168
254
  }
169
255
 
170
256
  /**
171
- * Requests notification permissions
172
- * This will show a dialog asking the user for permission
173
- * Only supported on iOS
257
+ * Adds an authentication listener to monitor user changes.
258
+ * @param {Object} props - The listener properties.
259
+ * @param {function} props.onUserChanged - Callback function triggered when the user changes.
260
+ * @returns {CourierAuthenticationListener} The created authentication listener.
174
261
  */
175
- public requestNotificationPermission(): Promise<string> {
176
- return CourierReactNativeModules.requestNotificationPermission();
262
+ public addAuthenticationListener(props: { onUserChanged: (userId?: string) => void }): CourierAuthenticationListener {
263
+
264
+ // Create a listener
265
+ const listenerId = `authentication_${Utils.generateUUID()}`;
266
+ const id = Modules.Shared.addAuthenticationListener(listenerId);
267
+
268
+ // Attach the listener
269
+ const listener = new CourierAuthenticationListener(id);
270
+ listener.onUserChanged = this.sharedBroadcaster.addListener(listenerId, (event) => props.onUserChanged(event));
271
+ this.authenticationListeners.set(id, listener);
272
+
273
+ return listener;
274
+
177
275
  }
178
276
 
179
277
  /**
180
- * Listens to push notification clicked and delivered messages
278
+ * Removes a specific authentication listener.
279
+ * @param {Object} props - The removal properties.
280
+ * @param {string} props.listenerId - The ID of the listener to remove.
281
+ * @returns {string} The ID of the removed listener.
181
282
  */
182
- public addPushNotificationListener(props: { onPushNotificationClicked?: (push: any) => void, onPushNotificationDelivered?: (push: any) => void }): CourierPushListener {
183
-
184
- const pushListener = new CourierPushListener();
283
+ public removeAuthenticationListener(props: { listenerId: string }): string {
185
284
 
186
- if (props.onPushNotificationClicked) {
187
- pushListener.onNotificationClickedListener = Utils.addEventListener(Events.Push.CLICKED, CourierEventEmitter, (event) => {
188
- try {
189
- props.onPushNotificationClicked!(JSON.parse(event));
190
- } catch (error) {
191
- console.log(error);
192
- }
193
- });
194
- }
285
+ // Remove the native listener
286
+ Modules.Shared.removeAuthenticationListener(props.listenerId);
195
287
 
196
- if (props.onPushNotificationDelivered) {
197
- pushListener.onNotificationDeliveredListener = Utils.addEventListener(Events.Push.DELIVERED, CourierEventEmitter, (event) => {
198
- try {
199
- props.onPushNotificationDelivered!(JSON.parse(event));
200
- } catch (error) {
201
- console.log(error);
202
- }
203
- });
288
+ // Remove the listener
289
+ if (this.authenticationListeners.has(props.listenerId)) {
290
+ const listener = this.authenticationListeners.get(props.listenerId);
291
+ listener?.onUserChanged?.remove();
292
+ this.authenticationListeners.delete(props.listenerId);
204
293
  }
205
294
 
206
- // When listener is registered
207
- // Attempt to fetch the last message that was clicked
208
- // This is needed for when the app is killed and the
209
- // user launched the app by clicking on a notifications
210
- CourierReactNativeModules.registerPushNotificationClickedOnKilledState();
211
-
212
- return pushListener
295
+ return props.listenerId;
213
296
 
214
297
  }
215
298
 
216
299
  /**
217
- * Gets the user id that is currently being used.
218
- * This is the user id associated with the network requests the sdk does.
300
+ * Removes all authentication listeners.
301
+ * This method clears all registered authentication listeners, both native and JavaScript.
219
302
  */
220
- get userId(): string | undefined {
221
- return CourierReactNativeModules.getUserId() ?? undefined
303
+ public removeAllAuthenticationListeners() {
304
+
305
+ // Remove all native listeners
306
+ Modules.Shared.removeAllAuthenticationListeners();
307
+
308
+ // Iterate through all authentication listeners
309
+ this.authenticationListeners.forEach((listener) => {
310
+ listener.onUserChanged?.remove();
311
+ });
312
+
313
+ // Clear the map of authentication listeners
314
+ this.authenticationListeners.clear();
315
+
222
316
  }
223
317
 
318
+ // Push
319
+
224
320
  /**
225
- * Gets the tenant id that is currently being used
321
+ * Retrieves all push notification tokens.
322
+ * @returns {Promise<Map<string, string>>} A promise that resolves to a Map of provider keys to tokens.
226
323
  */
227
- get tenantId(): string | undefined {
228
- return CourierReactNativeModules.getTenantId() ?? undefined
324
+ public async getAllTokens(): Promise<Map<string, string>> {
325
+ const tokensObject = await Modules.Shared.getAllTokens();
326
+ const tokensMap = new Map<string, string>();
327
+ for (const [key, value] of Object.entries(tokensObject)) {
328
+ tokensMap.set(key, value as string);
329
+ }
330
+ return tokensMap;
229
331
  }
230
332
 
231
333
  /**
232
- * Registers the auth token, client key and user id the sdk should use for requests
334
+ * Retrieves the push notification token for a specific key.
335
+ * @param {Object} props - The properties object.
336
+ * @param {string} props.key - The key associated with the token.
337
+ * @returns {Promise<string | undefined>} A promise that resolves to the token or undefined if not found.
233
338
  */
234
- public signIn(props: { accessToken: string, clientKey?: string, userId: string, tenantId?: string }): Promise<void> {
235
- return CourierReactNativeModules.signIn(props.accessToken, props.clientKey ?? null, props.userId, props.tenantId ?? null);
339
+ public async getToken(props: { key: string }): Promise<string | undefined> {
340
+ return await Modules.Shared.getToken(props.key);
236
341
  }
237
342
 
238
343
  /**
239
- * Removes the current user and credentials from the sdk
344
+ * Retrieves the push notification token for a specific provider.
345
+ * @param {Object} props - The properties object.
346
+ * @param {CourierPushProvider} props.provider - The push notification provider.
347
+ * @returns {Promise<string | undefined>} A promise that resolves to the token or undefined if not found.
240
348
  */
241
- public signOut(): Promise<void> {
242
- return CourierReactNativeModules.signOut();
349
+ public async getTokenForProvider(props: { provider: CourierPushProvider }): Promise<string | undefined> {
350
+ return await Modules.Shared.getToken(props.provider);
243
351
  }
244
352
 
245
353
  /**
246
- * Listens to authentication changes for the current user
354
+ * Sets the push notification token for a specific key.
355
+ * @param {Object} props - The properties object.
356
+ * @param {string} props.key - The key to associate with the token.
357
+ * @param {string} props.token - The push notification token.
358
+ * @returns {Promise<void>} A promise that resolves when the token is set.
247
359
  */
248
- public addAuthenticationListener(props: { onUserChanged: (userId?: string) => void }): CourierAuthenticationListener {
360
+ public async setToken(props: { key: string, token: string }): Promise<void> {
361
+ return await Modules.Shared.setToken(props.key, props.token);
362
+ }
249
363
 
250
- // Event listener id
251
- const authId = `authentication_${Utils.generateUUID()}`;
364
+ /**
365
+ * Sets the push notification token for a specific provider.
366
+ * @param {Object} props - The properties object.
367
+ * @param {CourierPushProvider} props.provider - The push notification provider.
368
+ * @param {string} props.token - The push notification token.
369
+ * @returns {Promise<void>} A promise that resolves when the token is set.
370
+ */
371
+ public async setTokenForProvider(props: { provider: CourierPushProvider, token: string }): Promise<void> {
372
+ return await Modules.Shared.setToken(props.provider, props.token);
373
+ }
252
374
 
253
- // Get the id
254
- const id = CourierReactNativeModules.addAuthenticationListener(authId);
375
+ /**
376
+ * Adds a push notification listener.
377
+ * @param {Object} props - The properties object.
378
+ * @param {function} [props.onPushNotificationClicked] - Callback function triggered when a push notification is clicked.
379
+ * @param {function} [props.onPushNotificationDelivered] - Callback function triggered when a push notification is delivered.
380
+ * @returns {CourierPushListener} The created push notification listener.
381
+ */
382
+ public addPushNotificationListener(props: { onPushNotificationClicked?: (push: any) => void, onPushNotificationDelivered?: (push: any) => void }): CourierPushListener {
383
+
384
+ const listenerId = `push_${Utils.generateUUID()}`;
255
385
 
256
- // Create the listener
257
- const listener = new CourierAuthenticationListener(id);
386
+ const pushListener = new CourierPushListener(
387
+ listenerId,
388
+ props.onPushNotificationClicked,
389
+ props.onPushNotificationDelivered
390
+ );
258
391
 
259
- // Add the event listener
260
- listener.onUserChanged = Utils.addEventListener(authId, CourierEventEmitter, (event) => props.onUserChanged(event));
392
+ // Cache the listener
393
+ this.pushListeners.set(listenerId, pushListener);
261
394
 
262
- // Add listener to manager
263
- this.authListeners.set(id, listener);
395
+ // When listener is registered
396
+ // Attempt to fetch the last message that was clicked
397
+ // This is needed for when the app is killed and the
398
+ // user launched the app by clicking on a notifications
399
+ Modules.System.registerPushNotificationClickedOnKilledState();
264
400
 
265
- return listener;
401
+ return pushListener;
266
402
 
267
403
  }
268
404
 
269
405
  /**
270
- * Removes an authentication listener
406
+ * Removes a specific push notification listener.
407
+ * @param {Object} props - The properties object.
408
+ * @param {string} props.listenerId - The ID of the listener to remove.
409
+ * @returns {string} The ID of the removed listener.
271
410
  */
272
- public removeAuthenticationListener(props: { listenerId: string }): string {
273
-
274
- // Remove the native listener
275
- CourierReactNativeModules.removeAuthenticationListener(props.listenerId);
411
+ public removePushNotificationListener(props: { listenerId: string }): string {
412
+ if (this.pushListeners.has(props.listenerId)) {
413
+ this.pushListeners.delete(props.listenerId);
414
+ }
415
+ return props.listenerId;
416
+ }
276
417
 
277
- // Remove the listener
278
- if (this.authListeners.has(props.listenerId)) {
418
+ /**
419
+ * Removes all push notification listeners.
420
+ */
421
+ public removeAllPushNotificationListeners() {
422
+ this.pushListeners.forEach((listener) => {
423
+ listener.remove();
424
+ });
425
+ this.pushListeners.clear();
426
+ }
279
427
 
280
- // Get the listener
281
- const listener = this.authListeners.get(props.listenerId);
282
- listener?.onUserChanged?.remove();
428
+ // Inbox
283
429
 
284
- // Remove the listener
285
- this.authListeners.delete(props.listenerId);
430
+ /**
431
+ * Gets the current pagination limit for inbox messages.
432
+ * @returns {number} The current pagination limit.
433
+ */
434
+ public get inboxPaginationLimit(): number {
435
+ return Modules.Shared.getInboxPaginationLimit();
436
+ }
286
437
 
287
- }
438
+ /**
439
+ * Sets the pagination limit for inbox messages.
440
+ * @param {number} limit - The new pagination limit to set.
441
+ */
442
+ public set inboxPaginationLimit(limit: number) {
443
+ Modules.Shared.setInboxPaginationLimit(limit);
444
+ }
288
445
 
289
- return props.listenerId;
446
+ /**
447
+ * Opens a specific message in the inbox.
448
+ * @param {Object} props - The properties object.
449
+ * @param {string} props.messageId - The ID of the message to open.
450
+ * @returns {Promise<void>} A promise that resolves when the message is opened.
451
+ */
452
+ public async openMessage(props: { messageId: string }): Promise<void> {
453
+ return await Modules.Shared.openMessage(props.messageId);
454
+ }
290
455
 
456
+ /**
457
+ * Registers a click event for a specific message in the inbox.
458
+ * @param {Object} props - The properties object.
459
+ * @param {string} props.messageId - The ID of the message that was clicked.
460
+ * @returns {Promise<void>} A promise that resolves when the click is registered.
461
+ */
462
+ public async clickMessage(props: { messageId: string }): Promise<void> {
463
+ return await Modules.Shared.clickMessage(props.messageId);
291
464
  }
292
465
 
293
466
  /**
294
- * Click an inbox message
467
+ * Marks a specific message as read in the inbox.
468
+ * @param {Object} props - The properties object.
469
+ * @param {string} props.messageId - The ID of the message to mark as read.
470
+ * @returns {Promise<void>} A promise that resolves when the message is marked as read.
295
471
  */
296
- public clickMessage(props: { messageId: string }): string {
297
- return CourierReactNativeModules.clickMessage(props.messageId);
472
+ public async readMessage(props: { messageId: string }): Promise<void> {
473
+ return await Modules.Shared.readMessage(props.messageId);
298
474
  }
299
475
 
300
476
  /**
301
- * Reads an inbox message
477
+ * Marks a specific message as unread in the inbox.
478
+ * @param {Object} props - The properties object.
479
+ * @param {string} props.messageId - The ID of the message to mark as unread.
480
+ * @returns {Promise<void>} A promise that resolves when the message is marked as unread.
302
481
  */
303
- public readMessage(props: { messageId: string }): string {
304
- return CourierReactNativeModules.readMessage(props.messageId);
482
+ public async unreadMessage(props: { messageId: string }): Promise<void> {
483
+ return await Modules.Shared.unreadMessage(props.messageId);
305
484
  }
306
485
 
307
486
  /**
308
- * Unreads an inbox message
487
+ * Archives a specific message in the inbox.
488
+ * @param {Object} props - The properties object.
489
+ * @param {string} props.messageId - The ID of the message to archive.
490
+ * @returns {Promise<void>} A promise that resolves when the message is archived.
309
491
  */
310
- public unreadMessage(props: { messageId: string }): string {
311
- return CourierReactNativeModules.unreadMessage(props.messageId);
492
+ public async archiveMessage(props: { messageId: string }): Promise<void> {
493
+ return await Modules.Shared.archiveMessage(props.messageId);
312
494
  }
313
495
 
314
496
  /**
315
- * Reads all the inbox messages
497
+ * Marks all messages in the inbox as read.
498
+ * @returns {Promise<void>} A promise that resolves when all messages are marked as read.
316
499
  */
317
- public readAllInboxMessages(): Promise<void> {
318
- return CourierReactNativeModules.readAllInboxMessages();
500
+ public async readAllInboxMessages(): Promise<void> {
501
+ return await Modules.Shared.readAllInboxMessages();
319
502
  }
320
503
 
321
504
  /**
322
- * Listens to changes for the inbox itself
505
+ * Adds a listener for inbox changes.
506
+ * @param {Object} props - The properties object.
507
+ * @param {Function} [props.onInitialLoad] - Callback function called when the inbox is initially loaded.
508
+ * @param {Function} [props.onError] - Callback function called when an error occurs. Receives the error message as a parameter.
509
+ * @param {Function} [props.onMessagesChanged] - Callback function called when messages change. Receives updated messages, unread count, total count, and pagination status.
510
+ * @returns {CourierInboxListener} A listener object that can be used to remove the listener later.
323
511
  */
324
512
  public addInboxListener(props: { onInitialLoad?: () => void, onError?: (error: string) => void, onMessagesChanged?: (messages: InboxMessage[], unreadMessageCount: number, totalMessageCount: number, canPaginate: boolean) => void }): CourierInboxListener {
325
513
 
@@ -330,7 +518,7 @@ class Courier {
330
518
  }
331
519
 
332
520
  // Set the listener id
333
- const id = CourierReactNativeModules.addInboxListener(
521
+ const id = Modules.Shared.addInboxListener(
334
522
  listenerIds.loading,
335
523
  listenerIds.error,
336
524
  listenerIds.messages
@@ -339,17 +527,29 @@ class Courier {
339
527
  // Create the initial listeners
340
528
  const listener = new CourierInboxListener(id);
341
529
 
342
- listener.onInitialLoad = Utils.addEventListener(listenerIds.loading, CourierEventEmitter, (_: any) => {
530
+ listener.onInitialLoad = this.sharedBroadcaster.addListener(listenerIds.loading, (_: any) => {
343
531
  props.onInitialLoad?.();
344
532
  });
345
533
 
346
- listener.onError = Utils.addEventListener(listenerIds.error, CourierEventEmitter, (event: any) => {
534
+ listener.onError = this.sharedBroadcaster.addListener(listenerIds.error, (event: any) => {
347
535
  props.onError?.(event);
348
536
  });
349
537
 
350
- listener.onMessagesChanged = Utils.addEventListener(listenerIds.messages, CourierEventEmitter, (event: any) => {
538
+ listener.onMessagesChanged = this.sharedBroadcaster.addListener(listenerIds.messages, (event: any) => {
539
+
540
+ // Convert JSON strings to InboxMessage objects
541
+ const convertedMessages: InboxMessage[] = event.messages.map((jsonString: string) => {
542
+ try {
543
+ const parsedMessage = JSON.parse(jsonString);
544
+ return parsedMessage as InboxMessage;
545
+ } catch (error) {
546
+ Courier.log(`Error parsing message: ${error}`);
547
+ return null;
548
+ }
549
+ }).filter((message: InboxMessage | null): message is InboxMessage => message !== null);
550
+
351
551
  props.onMessagesChanged?.(
352
- event.messages,
552
+ convertedMessages,
353
553
  event.unreadMessageCount,
354
554
  event.totalMessageCount,
355
555
  event.canPaginate,
@@ -364,12 +564,15 @@ class Courier {
364
564
  }
365
565
 
366
566
  /**
367
- * Removes an inbox listener
567
+ * Removes a specific inbox listener.
568
+ * @param {Object} props - The properties object.
569
+ * @param {string} props.listenerId - The ID of the listener to remove.
570
+ * @returns {string} The ID of the removed listener.
368
571
  */
369
572
  public removeInboxListener(props: { listenerId: string }): string {
370
573
 
371
574
  // Call native code
372
- CourierReactNativeModules.removeInboxListener(props.listenerId);
575
+ Modules.Shared.removeInboxListener(props.listenerId);
373
576
 
374
577
  // Remove the listener
375
578
  if (this.inboxListeners.has(props.listenerId)) {
@@ -390,49 +593,39 @@ class Courier {
390
593
  }
391
594
 
392
595
  /**
393
- * Refreshes the inbox
394
- * Useful for pull to refresh
596
+ * Removes all inbox listeners.
395
597
  */
396
- public async refreshInbox(): Promise<void> {
397
- return CourierReactNativeModules.refreshInbox();
398
- }
598
+ public removeAllInboxListeners() {
399
599
 
400
- /**
401
- * Fetches the next page of inbox messages
402
- * Returns the fetched inbox messages
403
- */
404
- public async fetchNextPageOfMessages(): Promise<InboxMessage[]> {
405
- return CourierReactNativeModules.fetchNextPageOfMessages();
406
- }
600
+ // Call native code
601
+ Modules.Shared.removeAllInboxListeners();
602
+
603
+ // Remove all items from inboxListeners
604
+ this.inboxListeners.forEach((listener) => {
605
+ listener?.onInitialLoad?.remove();
606
+ listener?.onError?.remove();
607
+ listener?.onMessagesChanged?.remove();
608
+ });
609
+ this.inboxListeners.clear();
407
610
 
408
- /**
409
- * Sets the pagination limit
410
- * Min = 1
411
- * Max = 100
412
- */
413
- public setInboxPaginationLimit(props: { limit: number }): void {
414
- CourierReactNativeModules.setInboxPaginationLimit(props.limit);
415
- }
416
-
417
- /**
418
- * Get all available preferences
419
- */
420
- public async getUserPreferences(props?: { paginationCursor: string }): Promise<CourierUserPreferences> {
421
- return CourierReactNativeModules.getUserPreferences(props?.paginationCursor ?? "");
422
611
  }
423
612
 
424
613
  /**
425
- * Get individual preferences topic
614
+ * Refreshes the inbox.
615
+ * Useful for pull-to-refresh functionality.
616
+ * @returns {Promise<void>} A promise that resolves when the inbox is refreshed.
426
617
  */
427
- public async getUserPreferencesTopic(props: { topicId: string }): Promise<CourierUserPreferencesTopic> {
428
- return CourierReactNativeModules.getUserPreferencesTopic(props.topicId);
618
+ public async refreshInbox(): Promise<void> {
619
+ return Modules.Shared.refreshInbox();
429
620
  }
430
621
 
431
622
  /**
432
- * Update individual preferences topic
623
+ * Fetches the next page of inbox messages.
624
+ * @returns {Promise<InboxMessage[]>} A promise that resolves with an array of fetched inbox messages.
433
625
  */
434
- public async putUserPreferencesTopic(props: { topicId: string, status: CourierUserPreferencesStatus, hasCustomRouting: boolean, customRouting: CourierUserPreferencesChannel[] }): Promise<void> {
435
- return CourierReactNativeModules.putUserPreferencesTopic(props.topicId, props.status, props.hasCustomRouting, props.customRouting);
626
+ public async fetchNextPageOfMessages(): Promise<InboxMessage[]> {
627
+ const messages = await Modules.Shared.fetchNextPageOfMessages();
628
+ return messages.map((message: string) => JSON.parse(message));
436
629
  }
437
630
 
438
631
  }