@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
@@ -100,8 +100,11 @@ dependencies {
100
100
  implementation "com.facebook.react:react-native:+"
101
101
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
102
102
 
103
+ // For converting to json
104
+ implementation 'com.google.code.gson:gson:2.11.0'
105
+
103
106
  // Courier Core SDK
104
- api 'com.github.trycourier:courier-android:3.4.1'
107
+ api 'com.github.trycourier:courier-android:4.3.1'
105
108
  api 'androidx.recyclerview:recyclerview:1.3.2'
106
109
 
107
110
  }
@@ -0,0 +1,441 @@
1
+ package com.courierreactnative
2
+
3
+ import com.courier.android.client.CourierClient
4
+ import com.courier.android.models.CourierDevice
5
+ import com.courier.android.models.CourierPreferenceChannel
6
+ import com.courier.android.models.CourierPreferenceStatus
7
+ import com.courier.android.models.CourierTrackingEvent
8
+ import com.facebook.react.bridge.Promise
9
+ import com.facebook.react.bridge.ReactApplicationContext
10
+ import com.facebook.react.bridge.ReactMethod
11
+ import com.facebook.react.bridge.ReadableArray
12
+ import com.facebook.react.bridge.ReadableMap
13
+ import kotlinx.coroutines.CoroutineScope
14
+ import kotlinx.coroutines.Dispatchers
15
+ import kotlinx.coroutines.launch
16
+ import java.util.UUID
17
+
18
+ class CourierClientModule(reactContext: ReactApplicationContext): ReactNativeModule(tag = "Client Error", name = "CourierClientModule", reactContext = reactContext) {
19
+
20
+ private var clients: MutableMap<String, CourierClient> = mutableMapOf()
21
+
22
+ @ReactMethod
23
+ fun addListener(type: String?) {
24
+ // Keep: Required for RN built in Event Emitter Calls.
25
+ }
26
+
27
+ @ReactMethod
28
+ fun removeListeners(type: Int?) {
29
+ // Keep: Required for RN built in Event Emitter Calls.
30
+ }
31
+
32
+ @ReactMethod(isBlockingSynchronousMethod = true)
33
+ fun addClient(options: ReadableMap): String {
34
+
35
+ val userId = options.getString("userId")
36
+ val showLogs = if (options.hasKey("showLogs")) options.getBoolean("showLogs") else null
37
+
38
+ if (userId == null || showLogs == null) {
39
+ return "invalid"
40
+ }
41
+
42
+ val client = CourierClient(
43
+ jwt = options.getString("jwt"),
44
+ clientKey = options.getString("clientKey"),
45
+ userId = userId,
46
+ connectionId = options.getString("connectionId"),
47
+ tenantId = options.getString("tenantId"),
48
+ showLogs = showLogs
49
+ )
50
+
51
+ val uuid = UUID.randomUUID().toString()
52
+ clients[uuid] = client
53
+
54
+ return uuid
55
+
56
+ }
57
+
58
+ @ReactMethod(isBlockingSynchronousMethod = true)
59
+ fun removeClient(clientId: String): String {
60
+ clients.remove(clientId)
61
+ return clientId
62
+ }
63
+
64
+ // Tokens
65
+
66
+ @ReactMethod
67
+ fun putUserToken(clientId: String, token: String, provider: String, device: ReadableMap?, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
68
+
69
+ val client = clients[clientId]
70
+ if (client == null) {
71
+ promise.rejectMissingClient()
72
+ return@launch
73
+ }
74
+
75
+ if (reactActivity == null) {
76
+ promise.rejectMissingContext()
77
+ return@launch
78
+ }
79
+
80
+ val courierDevice = device?.let {
81
+ return@let CourierDevice(
82
+ appId = it.getString("appId"),
83
+ adId = it.getString("adId"),
84
+ deviceId = it.getString("deviceId"),
85
+ platform = it.getString("platform"),
86
+ manufacturer = it.getString("manufacturer"),
87
+ model = it.getString("model")
88
+ )
89
+ }
90
+
91
+ try {
92
+ client.tokens.putUserToken(
93
+ token = token,
94
+ provider = provider,
95
+ device = courierDevice ?: CourierDevice.current(reactActivity!!)
96
+ )
97
+ promise.resolve(null)
98
+ } catch (e: Exception) {
99
+ promise.apiError(e)
100
+ }
101
+
102
+ }
103
+
104
+ @ReactMethod
105
+ fun deleteUserToken(clientId: String, token: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
106
+
107
+ val client = clients[clientId]
108
+ if (client == null) {
109
+ promise.rejectMissingClient()
110
+ return@launch
111
+ }
112
+
113
+ try {
114
+ client.tokens.deleteUserToken(
115
+ token = token,
116
+ )
117
+ promise.resolve(null)
118
+ } catch (e: Exception) {
119
+ promise.apiError(e)
120
+ }
121
+
122
+ }
123
+
124
+ // Brands
125
+
126
+ @ReactMethod
127
+ fun getBrand(clientId: String, brandId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
128
+
129
+ val client = clients[clientId]
130
+ if (client == null) {
131
+ promise.rejectMissingClient()
132
+ return@launch
133
+ }
134
+
135
+ try {
136
+ val brand = client.brands.getBrand(
137
+ brandId = brandId
138
+ )
139
+ val json = brand.toJson()
140
+ promise.resolve(json)
141
+ } catch (e: Exception) {
142
+ promise.apiError(e)
143
+ }
144
+
145
+ }
146
+
147
+ // Inbox
148
+
149
+ @ReactMethod
150
+ fun getMessages(clientId: String, paginationLimit: Int, startCursor: String?, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
151
+
152
+ val client = clients[clientId]
153
+ if (client == null) {
154
+ promise.rejectMissingClient()
155
+ return@launch
156
+ }
157
+
158
+ try {
159
+ val res = client.inbox.getMessages(
160
+ paginationLimit = paginationLimit,
161
+ startCursor = startCursor,
162
+ )
163
+ val json = res.toJson()
164
+ promise.resolve(json)
165
+ } catch (e: Exception) {
166
+ promise.apiError(e)
167
+ }
168
+
169
+ }
170
+
171
+ @ReactMethod
172
+ fun getArchivedMessages(clientId: String, paginationLimit: Int, startCursor: String?, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
173
+
174
+ val client = clients[clientId]
175
+ if (client == null) {
176
+ promise.rejectMissingClient()
177
+ return@launch
178
+ }
179
+
180
+ try {
181
+ val res = client.inbox.getArchivedMessages(
182
+ paginationLimit = paginationLimit,
183
+ startCursor = startCursor,
184
+ )
185
+ val json = res.toJson()
186
+ promise.resolve(json)
187
+ } catch (e: Exception) {
188
+ promise.apiError(e)
189
+ }
190
+
191
+ }
192
+
193
+ @ReactMethod
194
+ fun getMessageById(clientId: String, messageId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
195
+
196
+ val client = clients[clientId]
197
+ if (client == null) {
198
+ promise.rejectMissingClient()
199
+ return@launch
200
+ }
201
+
202
+ try {
203
+ val res = client.inbox.getMessage(
204
+ messageId = messageId,
205
+ )
206
+ val json = res.toJson()
207
+ promise.resolve(json)
208
+ } catch (e: Exception) {
209
+ promise.apiError(e)
210
+ }
211
+
212
+ }
213
+
214
+ @ReactMethod
215
+ fun getUnreadMessageCount(clientId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
216
+
217
+ val client = clients[clientId]
218
+ if (client == null) {
219
+ promise.rejectMissingClient()
220
+ return@launch
221
+ }
222
+
223
+ try {
224
+ val count = client.inbox.getUnreadMessageCount()
225
+ promise.resolve(count)
226
+ } catch (e: Exception) {
227
+ promise.apiError(e)
228
+ }
229
+
230
+ }
231
+
232
+ @ReactMethod
233
+ fun openMessage(clientId: String, messageId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
234
+
235
+ val client = clients[clientId]
236
+ if (client == null) {
237
+ promise.rejectMissingClient()
238
+ return@launch
239
+ }
240
+
241
+ try {
242
+ client.inbox.open(
243
+ messageId = messageId,
244
+ )
245
+ promise.resolve(null)
246
+ } catch (e: Exception) {
247
+ promise.apiError(e)
248
+ }
249
+
250
+ }
251
+
252
+ @ReactMethod
253
+ fun readMessage(clientId: String, messageId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
254
+
255
+ val client = clients[clientId]
256
+ if (client == null) {
257
+ promise.rejectMissingClient()
258
+ return@launch
259
+ }
260
+
261
+ try {
262
+ client.inbox.read(
263
+ messageId = messageId,
264
+ )
265
+ promise.resolve(null)
266
+ } catch (e: Exception) {
267
+ promise.apiError(e)
268
+ }
269
+
270
+ }
271
+
272
+ @ReactMethod
273
+ fun unreadMessage(clientId: String, messageId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
274
+
275
+ val client = clients[clientId]
276
+ if (client == null) {
277
+ promise.rejectMissingClient()
278
+ return@launch
279
+ }
280
+
281
+ try {
282
+ client.inbox.unread(
283
+ messageId = messageId,
284
+ )
285
+ promise.resolve(null)
286
+ } catch (e: Exception) {
287
+ promise.apiError(e)
288
+ }
289
+
290
+ }
291
+
292
+ @ReactMethod
293
+ fun clickMessage(clientId: String, messageId: String, trackingId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
294
+
295
+ val client = clients[clientId]
296
+ if (client == null) {
297
+ promise.rejectMissingClient()
298
+ return@launch
299
+ }
300
+
301
+ try {
302
+ client.inbox.click(
303
+ messageId = messageId,
304
+ trackingId = trackingId,
305
+ )
306
+ promise.resolve(null)
307
+ } catch (e: Exception) {
308
+ promise.apiError(e)
309
+ }
310
+
311
+ }
312
+
313
+ @ReactMethod
314
+ fun archiveMessage(clientId: String, messageId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
315
+
316
+ val client = clients[clientId]
317
+ if (client == null) {
318
+ promise.rejectMissingClient()
319
+ return@launch
320
+ }
321
+
322
+ try {
323
+ client.inbox.archive(
324
+ messageId = messageId,
325
+ )
326
+ promise.resolve(null)
327
+ } catch (e: Exception) {
328
+ promise.apiError(e)
329
+ }
330
+
331
+ }
332
+
333
+ @ReactMethod
334
+ fun readAllMessages(clientId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
335
+
336
+ val client = clients[clientId]
337
+ if (client == null) {
338
+ promise.rejectMissingClient()
339
+ return@launch
340
+ }
341
+
342
+ try {
343
+ client.inbox.readAll()
344
+ promise.resolve(null)
345
+ } catch (e: Exception) {
346
+ promise.apiError(e)
347
+ }
348
+
349
+ }
350
+
351
+ // Preferences
352
+
353
+ @ReactMethod
354
+ fun getUserPreferences(clientId: String, paginationCursor: String?, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
355
+
356
+ val client = clients[clientId]
357
+ if (client == null) {
358
+ promise.rejectMissingClient()
359
+ return@launch
360
+ }
361
+
362
+ try {
363
+ val res = client.preferences.getUserPreferences(
364
+ paginationCursor = paginationCursor
365
+ )
366
+ val json = res.toJson()
367
+ promise.resolve(json)
368
+ } catch (e: Exception) {
369
+ promise.apiError(e)
370
+ }
371
+
372
+ }
373
+
374
+ @ReactMethod
375
+ fun getUserPreferenceTopic(clientId: String, topicId: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
376
+
377
+ val client = clients[clientId]
378
+ if (client == null) {
379
+ promise.rejectMissingClient()
380
+ return@launch
381
+ }
382
+
383
+ try {
384
+ val res = client.preferences.getUserPreferenceTopic(
385
+ topicId = topicId
386
+ )
387
+ val json = res.toJson()
388
+ promise.resolve(json)
389
+ } catch (e: Exception) {
390
+ promise.apiError(e)
391
+ }
392
+
393
+ }
394
+
395
+ @ReactMethod
396
+ fun putUserPreferenceTopic(clientId: String, topicId: String, status: String, hasCustomRouting: Boolean, customRouting: ReadableArray, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
397
+
398
+ val client = clients[clientId]
399
+ if (client == null) {
400
+ promise.rejectMissingClient()
401
+ return@launch
402
+ }
403
+
404
+ try {
405
+ client.preferences.putUserPreferenceTopic(
406
+ topicId = topicId,
407
+ status = CourierPreferenceStatus.fromString(status),
408
+ hasCustomRouting = hasCustomRouting,
409
+ customRouting = customRouting.toArrayList().map { CourierPreferenceChannel.fromString(it as String) },
410
+ )
411
+ promise.resolve(null)
412
+ } catch (e: Exception) {
413
+ promise.apiError(e)
414
+ }
415
+
416
+ }
417
+
418
+ // Tracking
419
+
420
+ @ReactMethod
421
+ fun postTrackingUrl(clientId: String, url: String, event: String, promise: Promise) = CoroutineScope(Dispatchers.Main).launch {
422
+
423
+ val client = clients[clientId]
424
+ if (client == null) {
425
+ promise.rejectMissingClient()
426
+ return@launch
427
+ }
428
+
429
+ try {
430
+ client.tracking.postTrackingUrl(
431
+ url = url,
432
+ event = CourierTrackingEvent.valueOf(event.uppercase()),
433
+ )
434
+ promise.resolve(null)
435
+ } catch (e: Exception) {
436
+ promise.apiError(e)
437
+ }
438
+
439
+ }
440
+
441
+ }
@@ -51,7 +51,7 @@ class CourierInboxViewManager : SimpleViewManager<CourierInbox>() {
51
51
 
52
52
  view.setOnClickMessageListener { message, index ->
53
53
  val map = Arguments.createMap()
54
- map.putMap("message", message.toWritableMap())
54
+ map.putString("message", message.toJson())
55
55
  map.putInt("index", index)
56
56
  themedReactContext?.sendEvent(ON_CLICK_MESSAGE_AT_INDEX, map)
57
57
  }
@@ -64,7 +64,7 @@ class CourierInboxViewManager : SimpleViewManager<CourierInbox>() {
64
64
  view.setOnClickActionListener { action, message, index ->
65
65
  val map = Arguments.createMap()
66
66
  map.putMap("action", action.toWritableMap())
67
- map.putMap("message", message.toWritableMap())
67
+ map.putString("message", message.toJson())
68
68
  map.putInt("index", index)
69
69
  themedReactContext?.sendEvent(ON_CLICK_ACTION_AT_INDEX, map)
70
70
  }
@@ -5,15 +5,21 @@ import com.facebook.react.bridge.NativeModule
5
5
  import com.facebook.react.bridge.ReactApplicationContext
6
6
  import com.facebook.react.uimanager.ViewManager
7
7
 
8
-
9
8
  class CourierReactNativePackage : ReactPackage {
10
9
 
11
10
  override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
12
- return listOf(CourierReactNativeModule(reactContext))
11
+ return listOf(
12
+ CourierClientModule(reactContext),
13
+ CourierSharedModule(reactContext),
14
+ CourierSystemModule(reactContext),
15
+ )
13
16
  }
14
17
 
15
18
  override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
16
- return listOf(CourierInboxViewManager(), CourierPreferencesViewManager())
19
+ return listOf(
20
+ CourierInboxViewManager(),
21
+ CourierPreferencesViewManager(),
22
+ )
17
23
  }
18
24
 
19
25
  }