@trycourier/courier-react-native 3.2.1 → 4.0.4

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