@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
@@ -3,18 +3,42 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ Object.defineProperty(exports, "BrandClient", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _BrandClient.BrandClient;
10
+ }
11
+ });
6
12
  Object.defineProperty(exports, "CourierAuthenticationListener", {
7
13
  enumerable: true,
8
14
  get: function () {
9
15
  return _CourierAuthenticationListener.CourierAuthenticationListener;
10
16
  }
11
17
  });
18
+ Object.defineProperty(exports, "CourierBrandResponse", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _CourierBrand.CourierBrandResponse;
22
+ }
23
+ });
12
24
  Object.defineProperty(exports, "CourierButton", {
13
25
  enumerable: true,
14
26
  get: function () {
15
27
  return _CourierButton.CourierButton;
16
28
  }
17
29
  });
30
+ Object.defineProperty(exports, "CourierClient", {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _CourierClient.CourierClient;
34
+ }
35
+ });
36
+ Object.defineProperty(exports, "CourierDevice", {
37
+ enumerable: true,
38
+ get: function () {
39
+ return _CourierDevice.CourierDevice;
40
+ }
41
+ });
18
42
  Object.defineProperty(exports, "CourierFont", {
19
43
  enumerable: true,
20
44
  get: function () {
@@ -99,16 +123,28 @@ Object.defineProperty(exports, "CourierPushProvider", {
99
123
  return _CourierPushProvider.CourierPushProvider;
100
124
  }
101
125
  });
126
+ Object.defineProperty(exports, "CourierTrackingEvent", {
127
+ enumerable: true,
128
+ get: function () {
129
+ return _CourierTrackingEvent.CourierTrackingEvent;
130
+ }
131
+ });
102
132
  Object.defineProperty(exports, "CourierUserPreferencesChannel", {
103
133
  enumerable: true,
104
134
  get: function () {
105
- return _CourierUserPreferencesChannel.CourierUserPreferencesChannel;
135
+ return _CourierUserPreferences.CourierUserPreferencesChannel;
106
136
  }
107
137
  });
108
138
  Object.defineProperty(exports, "CourierUserPreferencesStatus", {
109
139
  enumerable: true,
110
140
  get: function () {
111
- return _CourierUserPreferencesStatus.CourierUserPreferencesStatus;
141
+ return _CourierUserPreferences.CourierUserPreferencesStatus;
142
+ }
143
+ });
144
+ Object.defineProperty(exports, "CourierUserPreferencesTopic", {
145
+ enumerable: true,
146
+ get: function () {
147
+ return _CourierUserPreferences.CourierUserPreferencesTopic;
112
148
  }
113
149
  });
114
150
  exports.default = void 0;
@@ -128,11 +164,17 @@ var _reactNative = require("react-native");
128
164
  var _CourierInboxListener = require("./models/CourierInboxListener");
129
165
  var _CourierPushListener = require("./models/CourierPushListener");
130
166
  var _CourierAuthenticationListener = require("./models/CourierAuthenticationListener");
167
+ var _Modules = require("./Modules");
168
+ var _Broadcaster = _interopRequireDefault(require("./Broadcaster"));
169
+ var _CourierClient = require("./client/CourierClient");
131
170
  var _utils = require("./utils");
171
+ var _BrandClient = require("./client/BrandClient");
172
+ var _CourierBrand = require("./models/CourierBrand");
173
+ var _CourierDevice = require("./models/CourierDevice");
132
174
  var _CourierInboxView = require("./views/CourierInboxView");
133
175
  var _CourierPreferencesView = require("./views/CourierPreferencesView");
134
- var _CourierUserPreferencesChannel = require("./models/CourierUserPreferencesChannel");
135
- var _CourierUserPreferencesStatus = require("./models/CourierUserPreferencesStatus");
176
+ var _CourierUserPreferences = require("./models/CourierUserPreferences");
177
+ var _CourierTrackingEvent = require("./models/CourierTrackingEvent");
136
178
  var _CourierPushProvider = require("./models/CourierPushProvider");
137
179
  var _CourierFont = require("./models/CourierFont");
138
180
  var _CourierButton = require("./models/CourierButton");
@@ -141,29 +183,31 @@ var _iOS_CourierCell = require("./models/iOS_CourierCell");
141
183
  var _iOS_CourierSheet = require("./models/iOS_CourierSheet");
142
184
  var _CourierInboxTheme = require("./models/CourierInboxTheme");
143
185
  var _CourierPreferencesTheme = require("./models/CourierPreferencesTheme");
186
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
144
187
  // Imports
145
188
 
146
189
  // Exports
147
190
 
148
- const LINKING_ERROR = `The package '@trycourier/courier-react-native' doesn't seem to be linked. Make sure: \n\n` + _reactNative.Platform.select({
149
- ios: "- You have run 'pod install'\n",
150
- default: ''
151
- }) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n';
152
- const CourierReactNativeModules = _reactNative.NativeModules.CourierReactNativeModule ? _reactNative.NativeModules.CourierReactNativeModule : new Proxy({}, {
153
- get() {
154
- throw new Error(LINKING_ERROR);
155
- }
156
- });
157
- const CourierEventEmitter = new _reactNative.NativeEventEmitter(_reactNative.NativeModules.CourierReactNativeModule);
158
191
  class Courier {
159
- _isDebugging = false;
160
- authListeners = new Map();
192
+ // Singleton
193
+
194
+ // Listeners
195
+ authenticationListeners = new Map();
161
196
  inboxListeners = new Map();
197
+ pushListeners = new Map();
198
+
199
+ // Broadcasting
200
+ systemBroadcaster = new _Broadcaster.default(_Modules.Modules.System);
201
+ sharedBroadcaster = new _Broadcaster.default(_Modules.Modules.Shared);
162
202
  constructor() {
163
203
  // Sets the initial SDK values
164
- // Defaults to React Native level debugging
165
- // and will show all foreground notification styles in iOS
166
- this.setDefaults();
204
+ // will show all foreground notification styles in iOS
205
+ Courier.setIOSForegroundPresentationOptions({
206
+ options: ['sound', 'badge', 'list', 'banner']
207
+ });
208
+
209
+ // Attach the push notification listeners
210
+ this.attachPushNotificationListeners();
167
211
  }
168
212
 
169
213
  // Returns the public shared instance
@@ -173,222 +217,408 @@ class Courier {
173
217
  }
174
218
  return this._sharedInstance;
175
219
  }
176
- async setDefaults() {
177
- this.setIsDebugging(__DEV__);
178
- this.iOSForegroundPresentationOptions({
179
- options: ['sound', 'badge', 'list', 'banner']
180
- });
181
- }
182
220
 
183
- /**
184
- * Tells native Courier SDKs to show or hide logs.
185
- * Defaults to the React __DEV__ mode
186
- */
187
- setIsDebugging(isDebugging) {
188
- var _this$debugListener;
189
- // Remove the existing listener if needed
190
- (_this$debugListener = this.debugListener) === null || _this$debugListener === void 0 ? void 0 : _this$debugListener.remove();
221
+ // Debugging
222
+
223
+ isDebugging = __DEV__;
191
224
 
192
- // Set a new listener
193
- // listener needs to be registered first to catch the event
194
- if (isDebugging) {
195
- this.debugListener = CourierEventEmitter.addListener(_utils.Events.Log.DEBUG_LOG, event => {
196
- console.log('\x1b[36m%s\x1b[0m', 'COURIER', event);
197
- });
225
+ // Show a log to the console
226
+ static log(message) {
227
+ if (Courier.shared.isDebugging) {
228
+ console.log(message);
198
229
  }
199
- CourierReactNativeModules.setDebugMode(isDebugging);
200
- this._isDebugging = isDebugging;
201
- return this._isDebugging;
202
230
  }
203
231
 
204
- /**
205
- * Returns the status of debugging
206
- */
207
- get isDebugging() {
208
- return this._isDebugging;
232
+ // System (Static)
233
+
234
+ attachPushNotificationListeners() {
235
+ var _this$pushNotificatio, _this$pushNotificatio2;
236
+ // Remove existing listeners
237
+ // Only allows one subscription to be active
238
+ (_this$pushNotificatio = this.pushNotificationClickedEmitter) === null || _this$pushNotificatio === void 0 ? void 0 : _this$pushNotificatio.remove();
239
+ (_this$pushNotificatio2 = this.pushNotificationDeliveredEmitter) === null || _this$pushNotificatio2 === void 0 ? void 0 : _this$pushNotificatio2.remove();
240
+
241
+ // When a push notification is clicked
242
+ this.pushNotificationClickedEmitter = this.systemBroadcaster.addListener(_utils.Events.Push.CLICKED, event => {
243
+ try {
244
+ const message = JSON.parse(event);
245
+ this.pushListeners.forEach(listener => {
246
+ if (listener.onPushNotificationClicked) {
247
+ listener.onPushNotificationClicked(message);
248
+ }
249
+ });
250
+ } catch (error) {
251
+ Courier.log(`Error parsing push notification clicked event: ${error}`);
252
+ }
253
+ });
254
+
255
+ // When a push notification is delivered
256
+ this.pushNotificationDeliveredEmitter = this.systemBroadcaster.addListener(_utils.Events.Push.DELIVERED, event => {
257
+ try {
258
+ const message = JSON.parse(event);
259
+ this.pushListeners.forEach(listener => {
260
+ if (listener.onPushNotificationDelivered) {
261
+ listener.onPushNotificationDelivered(message);
262
+ }
263
+ });
264
+ } catch (error) {
265
+ Courier.log(`Error parsing push notification delivered event: ${error}`);
266
+ }
267
+ });
209
268
  }
210
269
 
211
270
  /**
212
- * Sets the notification presentation options for iOS
271
+ * Sets the iOS foreground presentation options for push notifications.
272
+ * This method only works on iOS devices.
273
+ * @param props An object containing an array of iOSForegroundPresentationOptions.
274
+ * @returns A string indicating the result of the operation. Returns 'unsupported' on non-iOS platforms.
213
275
  */
214
- iOSForegroundPresentationOptions(props) {
276
+ static setIOSForegroundPresentationOptions(props) {
215
277
  // Only works on iOS
216
278
  if (_reactNative.Platform.OS !== 'ios') return 'unsupported';
217
279
  const normalizedParams = Array.from(new Set(props.options));
218
- return CourierReactNativeModules.iOSForegroundPresentationOptions({
280
+ return _Modules.Modules.System.setIOSForegroundPresentationOptions({
219
281
  options: normalizedParams
220
282
  });
221
283
  }
222
284
 
223
285
  /**
224
- * Gets a token for key
286
+ * Retrieves the current notification permission status.
287
+ * @returns A Promise that resolves to a string representing the current notification permission status.
225
288
  */
226
- getToken(props) {
227
- return CourierReactNativeModules.getToken(props.key);
228
- }
229
- getTokenForProvider(props) {
230
- return CourierReactNativeModules.getToken(props.provider);
289
+ static async getNotificationPermissionStatus() {
290
+ return await _Modules.Modules.System.getNotificationPermissionStatus();
231
291
  }
232
292
 
233
293
  /**
234
- * Sets the fcm token to be used by Courier
294
+ * Requests permission to send push notifications to the user.
295
+ * @returns A Promise that resolves to a string indicating the result of the permission request.
235
296
  */
236
- setToken(props) {
237
- return CourierReactNativeModules.setToken(props.key, props.token);
238
- }
239
- setTokenForProvider(props) {
240
- return CourierReactNativeModules.setToken(props.provider, props.token);
297
+ static async requestNotificationPermission() {
298
+ return await _Modules.Modules.System.requestNotificationPermission();
241
299
  }
242
300
 
243
301
  /**
244
- * Returns the notification permission status
245
- * Only supported on iOS
302
+ * Opens the settings page for the current app.
303
+ * This can be used to direct users to enable notifications if they've previously denied permission.
246
304
  */
247
- getNotificationPermissionStatus() {
248
- return CourierReactNativeModules.getNotificationPermissionStatus();
305
+ static openSettingsForApp() {
306
+ _Modules.Modules.System.openSettingsForApp();
249
307
  }
250
308
 
251
- /**
252
- * Requests notification permissions
253
- * This will show a dialog asking the user for permission
254
- * Only supported on iOS
255
- */
256
- requestNotificationPermission() {
257
- return CourierReactNativeModules.requestNotificationPermission();
258
- }
309
+ // Client
259
310
 
260
311
  /**
261
- * Listens to push notification clicked and delivered messages
312
+ * Gets the current CourierClient instance.
313
+ * @returns {CourierClient | undefined} The current CourierClient instance, or undefined if not initialized.
262
314
  */
263
- addPushNotificationListener(props) {
264
- const pushListener = new _CourierPushListener.CourierPushListener();
265
- if (props.onPushNotificationClicked) {
266
- pushListener.onNotificationClickedListener = _utils.Utils.addEventListener(_utils.Events.Push.CLICKED, CourierEventEmitter, event => {
267
- try {
268
- props.onPushNotificationClicked(JSON.parse(event));
269
- } catch (error) {
270
- console.log(error);
271
- }
272
- });
273
- }
274
- if (props.onPushNotificationDelivered) {
275
- pushListener.onNotificationDeliveredListener = _utils.Utils.addEventListener(_utils.Events.Push.DELIVERED, CourierEventEmitter, event => {
276
- try {
277
- props.onPushNotificationDelivered(JSON.parse(event));
278
- } catch (error) {
279
- console.log(error);
280
- }
281
- });
315
+ get client() {
316
+ const client = _Modules.Modules.Shared.getClient() ?? undefined;
317
+ if (!client) {
318
+ return undefined;
282
319
  }
283
-
284
- // When listener is registered
285
- // Attempt to fetch the last message that was clicked
286
- // This is needed for when the app is killed and the
287
- // user launched the app by clicking on a notifications
288
- CourierReactNativeModules.registerPushNotificationClickedOnKilledState();
289
- return pushListener;
320
+ const clientObj = JSON.parse(client);
321
+ return new _CourierClient.CourierClient({
322
+ userId: clientObj.userId,
323
+ showLogs: clientObj.showLogs,
324
+ jwt: clientObj.jwt,
325
+ clientKey: clientObj.clientKey,
326
+ connectionId: clientObj.connectionId,
327
+ tenantId: clientObj.tenantId
328
+ });
290
329
  }
291
330
 
331
+ // Authentication
332
+
292
333
  /**
293
- * Gets the user id that is currently being used.
294
- * This is the user id associated with the network requests the sdk does.
334
+ * Gets the current user ID.
335
+ * @returns {string | undefined} The current user ID, or undefined if not set.
295
336
  */
296
337
  get userId() {
297
- return CourierReactNativeModules.getUserId() ?? undefined;
338
+ return _Modules.Modules.Shared.getUserId() ?? undefined;
298
339
  }
299
340
 
300
341
  /**
301
- * Gets the tenant id that is currently being used
342
+ * Gets the current tenant ID.
343
+ * @returns {string | undefined} The current tenant ID, or undefined if not set.
302
344
  */
303
345
  get tenantId() {
304
- return CourierReactNativeModules.getTenantId() ?? undefined;
346
+ return _Modules.Modules.Shared.getTenantId() ?? undefined;
305
347
  }
306
348
 
307
349
  /**
308
- * Registers the auth token, client key and user id the sdk should use for requests
350
+ * Checks if a user is currently signed in.
351
+ * @returns {boolean} True if a user is signed in, false otherwise.
309
352
  */
310
- signIn(props) {
311
- return CourierReactNativeModules.signIn(props.accessToken, props.clientKey ?? null, props.userId, props.tenantId ?? null);
353
+ get isUserSignedIn() {
354
+ const isSignedIn = _Modules.Modules.Shared.getIsUserSignedIn() ?? 'false';
355
+ return isSignedIn.toLowerCase() === 'true';
312
356
  }
313
357
 
314
358
  /**
315
- * Removes the current user and credentials from the sdk
359
+ * Signs out the current user.
360
+ * @returns {Promise<void>} A promise that resolves when the sign out process is complete.
316
361
  */
317
- signOut() {
318
- return CourierReactNativeModules.signOut();
362
+ async signOut() {
363
+ return await _Modules.Modules.Shared.signOut();
319
364
  }
320
365
 
321
366
  /**
322
- * Listens to authentication changes for the current user
367
+ * Signs in a user with the provided credentials.
368
+ * @param {Object} props - The sign-in properties.
369
+ * @param {string} props.accessToken - The access token for authentication.
370
+ * @param {string} [props.clientKey] - The client key (optional).
371
+ * @param {string} props.userId - The user ID.
372
+ * @param {string} [props.tenantId] - The tenant ID (optional).
373
+ * @param {boolean} [props.showLogs] - Whether to show debug logs (defaults to __DEV__).
374
+ * @returns {Promise<void>} A promise that resolves when the sign-in process is complete.
323
375
  */
324
- addAuthenticationListener(props) {
325
- // Event listener id
326
- const authId = `authentication_${_utils.Utils.generateUUID()}`;
376
+ async signIn(props) {
377
+ this.isDebugging = props.showLogs ?? __DEV__;
378
+ return await _Modules.Modules.Shared.signIn(props.accessToken, props.clientKey ?? null, props.userId, props.tenantId ?? null, this.isDebugging);
379
+ }
327
380
 
328
- // Get the id
329
- const id = CourierReactNativeModules.addAuthenticationListener(authId);
381
+ /**
382
+ * Adds an authentication listener to monitor user changes.
383
+ * @param {Object} props - The listener properties.
384
+ * @param {function} props.onUserChanged - Callback function triggered when the user changes.
385
+ * @returns {CourierAuthenticationListener} The created authentication listener.
386
+ */
387
+ addAuthenticationListener(props) {
388
+ // Create a listener
389
+ const listenerId = `authentication_${_utils.Utils.generateUUID()}`;
390
+ const id = _Modules.Modules.Shared.addAuthenticationListener(listenerId);
330
391
 
331
- // Create the listener
392
+ // Attach the listener
332
393
  const listener = new _CourierAuthenticationListener.CourierAuthenticationListener(id);
333
-
334
- // Add the event listener
335
- listener.onUserChanged = _utils.Utils.addEventListener(authId, CourierEventEmitter, event => props.onUserChanged(event));
336
-
337
- // Add listener to manager
338
- this.authListeners.set(id, listener);
394
+ listener.onUserChanged = this.sharedBroadcaster.addListener(listenerId, event => props.onUserChanged(event));
395
+ this.authenticationListeners.set(id, listener);
339
396
  return listener;
340
397
  }
341
398
 
342
399
  /**
343
- * Removes an authentication listener
400
+ * Removes a specific authentication listener.
401
+ * @param {Object} props - The removal properties.
402
+ * @param {string} props.listenerId - The ID of the listener to remove.
403
+ * @returns {string} The ID of the removed listener.
344
404
  */
345
405
  removeAuthenticationListener(props) {
346
406
  // Remove the native listener
347
- CourierReactNativeModules.removeAuthenticationListener(props.listenerId);
407
+ _Modules.Modules.Shared.removeAuthenticationListener(props.listenerId);
348
408
 
349
409
  // Remove the listener
350
- if (this.authListeners.has(props.listenerId)) {
410
+ if (this.authenticationListeners.has(props.listenerId)) {
351
411
  var _listener$onUserChang;
352
- // Get the listener
353
- const listener = this.authListeners.get(props.listenerId);
412
+ const listener = this.authenticationListeners.get(props.listenerId);
354
413
  listener === null || listener === void 0 || (_listener$onUserChang = listener.onUserChanged) === null || _listener$onUserChang === void 0 ? void 0 : _listener$onUserChang.remove();
414
+ this.authenticationListeners.delete(props.listenerId);
415
+ }
416
+ return props.listenerId;
417
+ }
355
418
 
356
- // Remove the listener
357
- this.authListeners.delete(props.listenerId);
419
+ /**
420
+ * Removes all authentication listeners.
421
+ * This method clears all registered authentication listeners, both native and JavaScript.
422
+ */
423
+ removeAllAuthenticationListeners() {
424
+ // Remove all native listeners
425
+ _Modules.Modules.Shared.removeAllAuthenticationListeners();
426
+
427
+ // Iterate through all authentication listeners
428
+ this.authenticationListeners.forEach(listener => {
429
+ var _listener$onUserChang2;
430
+ (_listener$onUserChang2 = listener.onUserChanged) === null || _listener$onUserChang2 === void 0 ? void 0 : _listener$onUserChang2.remove();
431
+ });
432
+
433
+ // Clear the map of authentication listeners
434
+ this.authenticationListeners.clear();
435
+ }
436
+
437
+ // Push
438
+
439
+ /**
440
+ * Retrieves all push notification tokens.
441
+ * @returns {Promise<Map<string, string>>} A promise that resolves to a Map of provider keys to tokens.
442
+ */
443
+ async getAllTokens() {
444
+ const tokensObject = await _Modules.Modules.Shared.getAllTokens();
445
+ const tokensMap = new Map();
446
+ for (const [key, value] of Object.entries(tokensObject)) {
447
+ tokensMap.set(key, value);
448
+ }
449
+ return tokensMap;
450
+ }
451
+
452
+ /**
453
+ * Retrieves the push notification token for a specific key.
454
+ * @param {Object} props - The properties object.
455
+ * @param {string} props.key - The key associated with the token.
456
+ * @returns {Promise<string | undefined>} A promise that resolves to the token or undefined if not found.
457
+ */
458
+ async getToken(props) {
459
+ return await _Modules.Modules.Shared.getToken(props.key);
460
+ }
461
+
462
+ /**
463
+ * Retrieves the push notification token for a specific provider.
464
+ * @param {Object} props - The properties object.
465
+ * @param {CourierPushProvider} props.provider - The push notification provider.
466
+ * @returns {Promise<string | undefined>} A promise that resolves to the token or undefined if not found.
467
+ */
468
+ async getTokenForProvider(props) {
469
+ return await _Modules.Modules.Shared.getToken(props.provider);
470
+ }
471
+
472
+ /**
473
+ * Sets the push notification token for a specific key.
474
+ * @param {Object} props - The properties object.
475
+ * @param {string} props.key - The key to associate with the token.
476
+ * @param {string} props.token - The push notification token.
477
+ * @returns {Promise<void>} A promise that resolves when the token is set.
478
+ */
479
+ async setToken(props) {
480
+ return await _Modules.Modules.Shared.setToken(props.key, props.token);
481
+ }
482
+
483
+ /**
484
+ * Sets the push notification token for a specific provider.
485
+ * @param {Object} props - The properties object.
486
+ * @param {CourierPushProvider} props.provider - The push notification provider.
487
+ * @param {string} props.token - The push notification token.
488
+ * @returns {Promise<void>} A promise that resolves when the token is set.
489
+ */
490
+ async setTokenForProvider(props) {
491
+ return await _Modules.Modules.Shared.setToken(props.provider, props.token);
492
+ }
493
+
494
+ /**
495
+ * Adds a push notification listener.
496
+ * @param {Object} props - The properties object.
497
+ * @param {function} [props.onPushNotificationClicked] - Callback function triggered when a push notification is clicked.
498
+ * @param {function} [props.onPushNotificationDelivered] - Callback function triggered when a push notification is delivered.
499
+ * @returns {CourierPushListener} The created push notification listener.
500
+ */
501
+ addPushNotificationListener(props) {
502
+ const listenerId = `push_${_utils.Utils.generateUUID()}`;
503
+ const pushListener = new _CourierPushListener.CourierPushListener(listenerId, props.onPushNotificationClicked, props.onPushNotificationDelivered);
504
+
505
+ // Cache the listener
506
+ this.pushListeners.set(listenerId, pushListener);
507
+
508
+ // When listener is registered
509
+ // Attempt to fetch the last message that was clicked
510
+ // This is needed for when the app is killed and the
511
+ // user launched the app by clicking on a notifications
512
+ _Modules.Modules.System.registerPushNotificationClickedOnKilledState();
513
+ return pushListener;
514
+ }
515
+
516
+ /**
517
+ * Removes a specific push notification listener.
518
+ * @param {Object} props - The properties object.
519
+ * @param {string} props.listenerId - The ID of the listener to remove.
520
+ * @returns {string} The ID of the removed listener.
521
+ */
522
+ removePushNotificationListener(props) {
523
+ if (this.pushListeners.has(props.listenerId)) {
524
+ this.pushListeners.delete(props.listenerId);
358
525
  }
359
526
  return props.listenerId;
360
527
  }
361
528
 
362
529
  /**
363
- * Click an inbox message
530
+ * Removes all push notification listeners.
531
+ */
532
+ removeAllPushNotificationListeners() {
533
+ this.pushListeners.forEach(listener => {
534
+ listener.remove();
535
+ });
536
+ this.pushListeners.clear();
537
+ }
538
+
539
+ // Inbox
540
+
541
+ /**
542
+ * Gets the current pagination limit for inbox messages.
543
+ * @returns {number} The current pagination limit.
544
+ */
545
+ get inboxPaginationLimit() {
546
+ return _Modules.Modules.Shared.getInboxPaginationLimit();
547
+ }
548
+
549
+ /**
550
+ * Sets the pagination limit for inbox messages.
551
+ * @param {number} limit - The new pagination limit to set.
552
+ */
553
+ set inboxPaginationLimit(limit) {
554
+ _Modules.Modules.Shared.setInboxPaginationLimit(limit);
555
+ }
556
+
557
+ /**
558
+ * Opens a specific message in the inbox.
559
+ * @param {Object} props - The properties object.
560
+ * @param {string} props.messageId - The ID of the message to open.
561
+ * @returns {Promise<void>} A promise that resolves when the message is opened.
562
+ */
563
+ async openMessage(props) {
564
+ return await _Modules.Modules.Shared.openMessage(props.messageId);
565
+ }
566
+
567
+ /**
568
+ * Registers a click event for a specific message in the inbox.
569
+ * @param {Object} props - The properties object.
570
+ * @param {string} props.messageId - The ID of the message that was clicked.
571
+ * @returns {Promise<void>} A promise that resolves when the click is registered.
364
572
  */
365
- clickMessage(props) {
366
- return CourierReactNativeModules.clickMessage(props.messageId);
573
+ async clickMessage(props) {
574
+ return await _Modules.Modules.Shared.clickMessage(props.messageId);
367
575
  }
368
576
 
369
577
  /**
370
- * Reads an inbox message
578
+ * Marks a specific message as read in the inbox.
579
+ * @param {Object} props - The properties object.
580
+ * @param {string} props.messageId - The ID of the message to mark as read.
581
+ * @returns {Promise<void>} A promise that resolves when the message is marked as read.
371
582
  */
372
- readMessage(props) {
373
- return CourierReactNativeModules.readMessage(props.messageId);
583
+ async readMessage(props) {
584
+ return await _Modules.Modules.Shared.readMessage(props.messageId);
374
585
  }
375
586
 
376
587
  /**
377
- * Unreads an inbox message
588
+ * Marks a specific message as unread in the inbox.
589
+ * @param {Object} props - The properties object.
590
+ * @param {string} props.messageId - The ID of the message to mark as unread.
591
+ * @returns {Promise<void>} A promise that resolves when the message is marked as unread.
378
592
  */
379
- unreadMessage(props) {
380
- return CourierReactNativeModules.unreadMessage(props.messageId);
593
+ async unreadMessage(props) {
594
+ return await _Modules.Modules.Shared.unreadMessage(props.messageId);
381
595
  }
382
596
 
383
597
  /**
384
- * Reads all the inbox messages
598
+ * Archives a specific message in the inbox.
599
+ * @param {Object} props - The properties object.
600
+ * @param {string} props.messageId - The ID of the message to archive.
601
+ * @returns {Promise<void>} A promise that resolves when the message is archived.
385
602
  */
386
- readAllInboxMessages() {
387
- return CourierReactNativeModules.readAllInboxMessages();
603
+ async archiveMessage(props) {
604
+ return await _Modules.Modules.Shared.archiveMessage(props.messageId);
388
605
  }
389
606
 
390
607
  /**
391
- * Listens to changes for the inbox itself
608
+ * Marks all messages in the inbox as read.
609
+ * @returns {Promise<void>} A promise that resolves when all messages are marked as read.
610
+ */
611
+ async readAllInboxMessages() {
612
+ return await _Modules.Modules.Shared.readAllInboxMessages();
613
+ }
614
+
615
+ /**
616
+ * Adds a listener for inbox changes.
617
+ * @param {Object} props - The properties object.
618
+ * @param {Function} [props.onInitialLoad] - Callback function called when the inbox is initially loaded.
619
+ * @param {Function} [props.onError] - Callback function called when an error occurs. Receives the error message as a parameter.
620
+ * @param {Function} [props.onMessagesChanged] - Callback function called when messages change. Receives updated messages, unread count, total count, and pagination status.
621
+ * @returns {CourierInboxListener} A listener object that can be used to remove the listener later.
392
622
  */
393
623
  addInboxListener(props) {
394
624
  const listenerIds = {
@@ -398,21 +628,31 @@ class Courier {
398
628
  };
399
629
 
400
630
  // Set the listener id
401
- const id = CourierReactNativeModules.addInboxListener(listenerIds.loading, listenerIds.error, listenerIds.messages);
631
+ const id = _Modules.Modules.Shared.addInboxListener(listenerIds.loading, listenerIds.error, listenerIds.messages);
402
632
 
403
633
  // Create the initial listeners
404
634
  const listener = new _CourierInboxListener.CourierInboxListener(id);
405
- listener.onInitialLoad = _utils.Utils.addEventListener(listenerIds.loading, CourierEventEmitter, _ => {
635
+ listener.onInitialLoad = this.sharedBroadcaster.addListener(listenerIds.loading, _ => {
406
636
  var _props$onInitialLoad;
407
637
  (_props$onInitialLoad = props.onInitialLoad) === null || _props$onInitialLoad === void 0 ? void 0 : _props$onInitialLoad.call(props);
408
638
  });
409
- listener.onError = _utils.Utils.addEventListener(listenerIds.error, CourierEventEmitter, event => {
639
+ listener.onError = this.sharedBroadcaster.addListener(listenerIds.error, event => {
410
640
  var _props$onError;
411
641
  (_props$onError = props.onError) === null || _props$onError === void 0 ? void 0 : _props$onError.call(props, event);
412
642
  });
413
- listener.onMessagesChanged = _utils.Utils.addEventListener(listenerIds.messages, CourierEventEmitter, event => {
643
+ listener.onMessagesChanged = this.sharedBroadcaster.addListener(listenerIds.messages, event => {
414
644
  var _props$onMessagesChan;
415
- (_props$onMessagesChan = props.onMessagesChanged) === null || _props$onMessagesChan === void 0 ? void 0 : _props$onMessagesChan.call(props, event.messages, event.unreadMessageCount, event.totalMessageCount, event.canPaginate);
645
+ // Convert JSON strings to InboxMessage objects
646
+ const convertedMessages = event.messages.map(jsonString => {
647
+ try {
648
+ const parsedMessage = JSON.parse(jsonString);
649
+ return parsedMessage;
650
+ } catch (error) {
651
+ Courier.log(`Error parsing message: ${error}`);
652
+ return null;
653
+ }
654
+ }).filter(message => message !== null);
655
+ (_props$onMessagesChan = props.onMessagesChanged) === null || _props$onMessagesChan === void 0 ? void 0 : _props$onMessagesChan.call(props, convertedMessages, event.unreadMessageCount, event.totalMessageCount, event.canPaginate);
416
656
  });
417
657
 
418
658
  // Add listener to manager
@@ -421,11 +661,14 @@ class Courier {
421
661
  }
422
662
 
423
663
  /**
424
- * Removes an inbox listener
664
+ * Removes a specific inbox listener.
665
+ * @param {Object} props - The properties object.
666
+ * @param {string} props.listenerId - The ID of the listener to remove.
667
+ * @returns {string} The ID of the removed listener.
425
668
  */
426
669
  removeInboxListener(props) {
427
670
  // Call native code
428
- CourierReactNativeModules.removeInboxListener(props.listenerId);
671
+ _Modules.Modules.Shared.removeInboxListener(props.listenerId);
429
672
 
430
673
  // Remove the listener
431
674
  if (this.inboxListeners.has(props.listenerId)) {
@@ -443,49 +686,38 @@ class Courier {
443
686
  }
444
687
 
445
688
  /**
446
- * Refreshes the inbox
447
- * Useful for pull to refresh
448
- */
449
- async refreshInbox() {
450
- return CourierReactNativeModules.refreshInbox();
451
- }
452
-
453
- /**
454
- * Fetches the next page of inbox messages
455
- * Returns the fetched inbox messages
456
- */
457
- async fetchNextPageOfMessages() {
458
- return CourierReactNativeModules.fetchNextPageOfMessages();
459
- }
460
-
461
- /**
462
- * Sets the pagination limit
463
- * Min = 1
464
- * Max = 100
465
- */
466
- setInboxPaginationLimit(props) {
467
- CourierReactNativeModules.setInboxPaginationLimit(props.limit);
468
- }
469
-
470
- /**
471
- * Get all available preferences
689
+ * Removes all inbox listeners.
472
690
  */
473
- async getUserPreferences(props) {
474
- return CourierReactNativeModules.getUserPreferences((props === null || props === void 0 ? void 0 : props.paginationCursor) ?? "");
691
+ removeAllInboxListeners() {
692
+ // Call native code
693
+ _Modules.Modules.Shared.removeAllInboxListeners();
694
+
695
+ // Remove all items from inboxListeners
696
+ this.inboxListeners.forEach(listener => {
697
+ var _listener$onInitialLo2, _listener$onError2, _listener$onMessagesC2;
698
+ listener === null || listener === void 0 || (_listener$onInitialLo2 = listener.onInitialLoad) === null || _listener$onInitialLo2 === void 0 ? void 0 : _listener$onInitialLo2.remove();
699
+ listener === null || listener === void 0 || (_listener$onError2 = listener.onError) === null || _listener$onError2 === void 0 ? void 0 : _listener$onError2.remove();
700
+ listener === null || listener === void 0 || (_listener$onMessagesC2 = listener.onMessagesChanged) === null || _listener$onMessagesC2 === void 0 ? void 0 : _listener$onMessagesC2.remove();
701
+ });
702
+ this.inboxListeners.clear();
475
703
  }
476
704
 
477
705
  /**
478
- * Get individual preferences topic
706
+ * Refreshes the inbox.
707
+ * Useful for pull-to-refresh functionality.
708
+ * @returns {Promise<void>} A promise that resolves when the inbox is refreshed.
479
709
  */
480
- async getUserPreferencesTopic(props) {
481
- return CourierReactNativeModules.getUserPreferencesTopic(props.topicId);
710
+ async refreshInbox() {
711
+ return _Modules.Modules.Shared.refreshInbox();
482
712
  }
483
713
 
484
714
  /**
485
- * Update individual preferences topic
715
+ * Fetches the next page of inbox messages.
716
+ * @returns {Promise<InboxMessage[]>} A promise that resolves with an array of fetched inbox messages.
486
717
  */
487
- async putUserPreferencesTopic(props) {
488
- return CourierReactNativeModules.putUserPreferencesTopic(props.topicId, props.status, props.hasCustomRouting, props.customRouting);
718
+ async fetchNextPageOfMessages() {
719
+ const messages = await _Modules.Modules.Shared.fetchNextPageOfMessages();
720
+ return messages.map(message => JSON.parse(message));
489
721
  }
490
722
  }
491
723
  var _default = Courier;