@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
@@ -1,13 +1,21 @@
1
1
  #import <React/RCTBridgeModule.h>
2
2
 
3
- @interface RCT_EXTERN_MODULE(CourierReactNativeModule, NSObject)
3
+ @interface RCT_EXTERN_MODULE(CourierSharedModule, NSObject)
4
4
 
5
5
  RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
6
- setDebugMode: (BOOL)isDebugging
6
+ getClient
7
7
  )
8
8
 
9
9
  RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
10
- iOSForegroundPresentationOptions: (NSDictionary*)params
10
+ getUserId
11
+ )
12
+
13
+ RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
14
+ getTenantId
15
+ )
16
+
17
+ RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
18
+ getIsUserSignedIn
11
19
  )
12
20
 
13
21
  RCT_EXTERN_METHOD(
@@ -15,6 +23,7 @@ RCT_EXTERN_METHOD(
15
23
  withClientKey: (NSString*)clientKey
16
24
  withUserId: (NSString*)userId
17
25
  withTenantId: (NSString*)tenantId
26
+ withShowLogs: (BOOL*)showLogs
18
27
  withResolver: (RCTPromiseResolveBlock)resolve
19
28
  withRejecter: (RCTPromiseRejectBlock)reject
20
29
  )
@@ -25,54 +34,71 @@ RCT_EXTERN_METHOD(
25
34
  )
26
35
 
27
36
  RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
28
- getUserId
37
+ addAuthenticationListener: (NSString*)authId
29
38
  )
30
39
 
31
40
  RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
32
- getTenantId
41
+ removeAuthenticationListener: (NSString*)listenerId
33
42
  )
34
43
 
35
44
  RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
36
- addAuthenticationListener: (NSString*)authId
45
+ removeAllAuthenticationListeners
37
46
  )
38
47
 
39
- RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
40
- removeAuthenticationListener: (NSString*)listenerId
48
+ RCT_EXTERN_METHOD(
49
+ getAllTokens: (RCTPromiseResolveBlock)resolve
50
+ withRejecter: (RCTPromiseRejectBlock)reject
41
51
  )
42
52
 
43
53
  RCT_EXTERN_METHOD(
44
- getNotificationPermissionStatus: (RCTPromiseResolveBlock)resolve
54
+ getToken: (NSString*)provider
55
+ withResolver: (RCTPromiseResolveBlock)resolve
45
56
  withRejecter: (RCTPromiseRejectBlock)reject
46
57
  )
47
58
 
48
59
  RCT_EXTERN_METHOD(
49
- requestNotificationPermission: (RCTPromiseResolveBlock)resolve
60
+ setToken: (NSString*)provider
61
+ withToken: (NSString*)token
62
+ withResolver: (RCTPromiseResolveBlock)resolve
50
63
  withRejecter: (RCTPromiseRejectBlock)reject
51
64
  )
52
65
 
66
+ RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
67
+ getInboxPaginationLimit
68
+ )
69
+
70
+ RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
71
+ setInboxPaginationLimit: (double)limit
72
+ )
73
+
53
74
  RCT_EXTERN_METHOD(
54
- setToken: (NSString*)key
55
- withToken: (NSString*)token
75
+ openMessage: (NSString*)messageId
56
76
  withResolver: (RCTPromiseResolveBlock)resolve
57
77
  withRejecter: (RCTPromiseRejectBlock)reject
58
78
  )
59
79
 
60
80
  RCT_EXTERN_METHOD(
61
- getToken: (NSString*)key
81
+ archiveMessage: (NSString*)messageId
62
82
  withResolver: (RCTPromiseResolveBlock)resolve
63
83
  withRejecter: (RCTPromiseRejectBlock)reject
64
84
  )
65
85
 
66
- RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
86
+ RCT_EXTERN_METHOD(
67
87
  clickMessage: (NSString*)messageId
88
+ withResolver: (RCTPromiseResolveBlock)resolve
89
+ withRejecter: (RCTPromiseRejectBlock)reject
68
90
  )
69
91
 
70
- RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
92
+ RCT_EXTERN_METHOD(
71
93
  readMessage: (NSString*)messageId
94
+ withResolver: (RCTPromiseResolveBlock)resolve
95
+ withRejecter: (RCTPromiseRejectBlock)reject
72
96
  )
73
97
 
74
- RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
98
+ RCT_EXTERN_METHOD(
75
99
  unreadMessage: (NSString*)messageId
100
+ withResolver: (RCTPromiseResolveBlock)resolve
101
+ withRejecter: (RCTPromiseRejectBlock)reject
76
102
  )
77
103
 
78
104
  RCT_EXTERN_METHOD(
@@ -90,6 +116,10 @@ RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
90
116
  removeInboxListener: (NSString*)listenerId
91
117
  )
92
118
 
119
+ RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
120
+ removeAllInboxListeners
121
+ )
122
+
93
123
  RCT_EXTERN_METHOD(
94
124
  refreshInbox: (RCTPromiseResolveBlock)resolve
95
125
  withRejecter: (RCTPromiseRejectBlock)reject
@@ -100,37 +130,176 @@ RCT_EXTERN_METHOD(
100
130
  withRejecter: (RCTPromiseRejectBlock)reject
101
131
  )
102
132
 
133
+ + (BOOL)requiresMainQueueSetup
134
+ {
135
+ return YES;
136
+ }
137
+
138
+ @end
139
+
140
+ @interface RCT_EXTERN_MODULE(CourierClientModule, NSObject)
141
+
103
142
  RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
104
- setInboxPaginationLimit: (double)limit
143
+ addClient: (NSDictionary*)options
144
+ )
145
+
146
+ RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
147
+ removeClient: (NSString*)clientId
148
+ )
149
+
150
+ RCT_EXTERN_METHOD(
151
+ putUserToken: (NSString*)clientId
152
+ withToken: (NSString*)token
153
+ withProvider: (NSString*)provider
154
+ withDevice: (NSDictionary*)device
155
+ withResolver: (RCTPromiseResolveBlock)resolve
156
+ withRejecter: (RCTPromiseRejectBlock)reject
157
+ )
158
+
159
+ RCT_EXTERN_METHOD(
160
+ deleteUserToken: (NSString*)clientId
161
+ withToken: (NSString*)token
162
+ withResolver: (RCTPromiseResolveBlock)resolve
163
+ withRejecter: (RCTPromiseRejectBlock)reject
164
+ )
165
+
166
+ RCT_EXTERN_METHOD(
167
+ getBrand: (NSString*)clientId
168
+ withBrandId: (NSString*)brandId
169
+ withResolver: (RCTPromiseResolveBlock)resolve
170
+ withRejecter: (RCTPromiseRejectBlock)reject
105
171
  )
106
172
 
107
173
  RCT_EXTERN_METHOD(
108
- getUserPreferences: (NSString*)paginationCursor
174
+ getMessages: (NSString*)clientId
175
+ withPaginationLimit: (double)paginationLimit
176
+ withStartCursor: (NSString*)startCursor
109
177
  withResolver: (RCTPromiseResolveBlock)resolve
110
178
  withRejecter: (RCTPromiseRejectBlock)reject
111
179
  )
112
180
 
113
181
  RCT_EXTERN_METHOD(
114
- getUserPreferencesTopic: (NSString*)topicId
182
+ getArchivedMessages: (NSString*)clientId
183
+ withPaginationLimit: (double)paginationLimit
184
+ withStartCursor: (NSString*)startCursor
115
185
  withResolver: (RCTPromiseResolveBlock)resolve
116
186
  withRejecter: (RCTPromiseRejectBlock)reject
117
187
  )
118
188
 
119
189
  RCT_EXTERN_METHOD(
120
- getUserPreferencesTopic: (NSString*)topicId
190
+ getMessageById: (NSString*)clientId
191
+ withMessageId: (NSString*)messageId
121
192
  withResolver: (RCTPromiseResolveBlock)resolve
122
193
  withRejecter: (RCTPromiseRejectBlock)reject
123
194
  )
124
195
 
125
196
  RCT_EXTERN_METHOD(
126
- putUserPreferencesTopic: (NSString*)topicId
197
+ getUnreadMessageCount: (NSString*)clientId
198
+ withResolver: (RCTPromiseResolveBlock)resolve
199
+ withRejecter: (RCTPromiseRejectBlock)reject
200
+ )
201
+
202
+ RCT_EXTERN_METHOD(
203
+ openMessage: (NSString*)clientId
204
+ withMessageId: (NSString*)messageId
205
+ withResolver: (RCTPromiseResolveBlock)resolve
206
+ withRejecter: (RCTPromiseRejectBlock)reject
207
+ )
208
+
209
+ RCT_EXTERN_METHOD(
210
+ readMessage: (NSString*)clientId
211
+ withMessageId: (NSString*)messageId
212
+ withResolver: (RCTPromiseResolveBlock)resolve
213
+ withRejecter: (RCTPromiseRejectBlock)reject
214
+ )
215
+
216
+ RCT_EXTERN_METHOD(
217
+ unreadMessage: (NSString*)clientId
218
+ withMessageId: (NSString*)messageId
219
+ withResolver: (RCTPromiseResolveBlock)resolve
220
+ withRejecter: (RCTPromiseRejectBlock)reject
221
+ )
222
+
223
+ RCT_EXTERN_METHOD(
224
+ clickMessage: (NSString*)clientId
225
+ withMessageId: (NSString*)messageId
226
+ withTrackingId: (NSString*)trackingId
227
+ withResolver: (RCTPromiseResolveBlock)resolve
228
+ withRejecter: (RCTPromiseRejectBlock)reject
229
+ )
230
+
231
+ RCT_EXTERN_METHOD(
232
+ archiveMessage: (NSString*)clientId
233
+ withMessageId: (NSString*)messageId
234
+ withResolver: (RCTPromiseResolveBlock)resolve
235
+ withRejecter: (RCTPromiseRejectBlock)reject
236
+ )
237
+
238
+ RCT_EXTERN_METHOD(
239
+ readAllMessages: (NSString*)clientId
240
+ withResolver: (RCTPromiseResolveBlock)resolve
241
+ withRejecter: (RCTPromiseRejectBlock)reject
242
+ )
243
+
244
+ RCT_EXTERN_METHOD(
245
+ getUserPreferences: (NSString*)clientId
246
+ withPaginationCursor: (NSString*)paginationCursor
247
+ withResolver: (RCTPromiseResolveBlock)resolve
248
+ withRejecter: (RCTPromiseRejectBlock)reject
249
+ )
250
+
251
+ RCT_EXTERN_METHOD(
252
+ getUserPreferenceTopic: (NSString*)clientId
253
+ withTopicId: (NSString*)topicId
254
+ withResolver: (RCTPromiseResolveBlock)resolve
255
+ withRejecter: (RCTPromiseRejectBlock)reject
256
+ )
257
+
258
+ RCT_EXTERN_METHOD(
259
+ putUserPreferenceTopic: (NSString*)clientId
260
+ withTopicId: (NSString*)topicId
127
261
  withStatus: (NSString*)status
128
- withHasCustomRouting: (BOOL*)hasCustomRouting
129
- withCustomRouting: (NSArray*)customRouting
262
+ withHasCustomRouting: (BOOL)hasCustomRouting
263
+ withCustomRouting: (NSArray<NSString*>*)customRouting
130
264
  withResolver: (RCTPromiseResolveBlock)resolve
131
265
  withRejecter: (RCTPromiseRejectBlock)reject
132
266
  )
133
267
 
268
+ RCT_EXTERN_METHOD(
269
+ postTrackingUrl: (NSString*)clientId
270
+ withUrl: (NSString*)url
271
+ withEvent: (NSString*)event
272
+ withResolver: (RCTPromiseResolveBlock)resolve
273
+ withRejecter: (RCTPromiseRejectBlock)reject
274
+ )
275
+
276
+ + (BOOL)requiresMainQueueSetup
277
+ {
278
+ return YES;
279
+ }
280
+
281
+ @end
282
+
283
+ @interface RCT_EXTERN_MODULE(CourierSystemModule, NSObject)
284
+
285
+ RCT_EXTERN_METHOD(
286
+ openSettingsForApp
287
+ )
288
+
289
+ RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
290
+ setIOSForegroundPresentationOptions: (NSDictionary*)params
291
+ )
292
+
293
+ RCT_EXTERN_METHOD(
294
+ getNotificationPermissionStatus: (RCTPromiseResolveBlock)resolve
295
+ withRejecter: (RCTPromiseRejectBlock)reject
296
+ )
297
+
298
+ RCT_EXTERN_METHOD(
299
+ requestNotificationPermission: (RCTPromiseResolveBlock)resolve
300
+ withRejecter: (RCTPromiseRejectBlock)reject
301
+ )
302
+
134
303
  RCT_EXTERN_METHOD(
135
304
  registerPushNotificationClickedOnKilledState
136
305
  )
@@ -0,0 +1,412 @@
1
+ import Courier_iOS
2
+
3
+ @objc(CourierSharedModule)
4
+ class CourierSharedModule: CourierReactNativeEventEmitter {
5
+
6
+ private var nativeEmitters = [String]()
7
+ private var authenticationListeners: [String: CourierAuthenticationListener] = [:]
8
+ private var inboxListeners: [String: CourierInboxListener] = [:]
9
+
10
+ override func stopObserving() {
11
+ removeAllAuthenticationListeners()
12
+ removeAllInboxListeners()
13
+ }
14
+
15
+ // MARK: Client
16
+
17
+ @objc func getClient() -> String? {
18
+
19
+ guard let options = Courier.shared.client?.options else {
20
+ return nil
21
+ }
22
+
23
+ do {
24
+
25
+ let dictionary = [
26
+ "jwt": options.jwt as Any,
27
+ "clientKey": options.clientKey as Any,
28
+ "userId": options.userId as Any,
29
+ "connectionId": options.connectionId as Any,
30
+ "tenantId": options.tenantId as Any,
31
+ "showLogs": options.showLogs as Any
32
+ ]
33
+ .compactMapValues { $0 }
34
+
35
+ let jsonData = try JSONSerialization.data(
36
+ withJSONObject: dictionary,
37
+ options: .prettyPrinted
38
+ )
39
+
40
+ guard let jsonString = String(data: jsonData, encoding: .utf8) else {
41
+ return nil
42
+ }
43
+
44
+ return jsonString
45
+
46
+ } catch {
47
+ return nil
48
+ }
49
+
50
+ }
51
+
52
+ // MARK: Authentication
53
+
54
+ @objc func getUserId() -> String? {
55
+ return Courier.shared.userId
56
+ }
57
+
58
+ @objc func getTenantId() -> String? {
59
+ return Courier.shared.tenantId
60
+ }
61
+
62
+ @objc func getIsUserSignedIn() -> String {
63
+ return String(Courier.shared.isUserSignedIn)
64
+ }
65
+
66
+ @objc(signIn:withClientKey:withUserId:withTenantId:withShowLogs:withResolver:withRejecter:)
67
+ func signIn(accessToken: NSString, clientKey: NSString?, userId: NSString, tenantId: NSString?, showLogs: Bool, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
68
+
69
+ let userId = userId as String
70
+ let tenantId = tenantId as? String
71
+ let accessToken = accessToken as String
72
+ let clientKey = clientKey as? String
73
+
74
+ Task {
75
+
76
+ await Courier.shared.signIn(
77
+ userId: userId,
78
+ tenantId: tenantId,
79
+ accessToken: accessToken,
80
+ clientKey: clientKey,
81
+ showLogs: showLogs
82
+ )
83
+
84
+ resolve(nil)
85
+
86
+ }
87
+
88
+ }
89
+
90
+ @objc(signOut:withRejecter:)
91
+ func signOut(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
92
+
93
+ Task {
94
+ await Courier.shared.signOut()
95
+ resolve(nil)
96
+ }
97
+
98
+ }
99
+
100
+ @objc(addAuthenticationListener:)
101
+ func addAuthenticationListener(listenerId: String) -> String {
102
+
103
+ nativeEmitters.append(listenerId)
104
+
105
+ let listener = Courier.shared.addAuthenticationListener { [weak self] userId in
106
+ self?.broadcast(
107
+ name: listenerId,
108
+ body: userId
109
+ )
110
+ }
111
+
112
+ authenticationListeners[listenerId] = listener
113
+
114
+ return listenerId
115
+
116
+ }
117
+
118
+ @objc(removeAuthenticationListener:)
119
+ func removeAuthenticationListener(listenerId: NSString) -> String {
120
+
121
+ let id = listenerId as String
122
+
123
+ let listener = authenticationListeners[id]
124
+
125
+ // Disable the listener
126
+ listener?.remove()
127
+
128
+ // Remove the id from the map
129
+ authenticationListeners.removeValue(forKey: id)
130
+
131
+ return id
132
+
133
+ }
134
+
135
+ @discardableResult @objc func removeAllAuthenticationListeners() -> String? {
136
+
137
+ for value in authenticationListeners.values {
138
+ value.remove()
139
+ }
140
+
141
+ authenticationListeners.removeAll()
142
+
143
+ return nil
144
+
145
+ }
146
+
147
+ // MARK: Push
148
+
149
+ @objc(getAllTokens:withRejecter:)
150
+ func getAllTokens(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
151
+
152
+ Task {
153
+
154
+ let tokens = await Courier.shared.tokens
155
+ resolve(tokens)
156
+
157
+ }
158
+
159
+ }
160
+
161
+ @objc(getToken:withResolver:withRejecter:)
162
+ func getToken(provider: NSString, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
163
+
164
+ let provider = provider as String
165
+
166
+ Task {
167
+
168
+ let token = await Courier.shared.getToken(for: provider)
169
+ resolve(token)
170
+
171
+ }
172
+
173
+ }
174
+
175
+ @objc(setToken:withToken:withResolver:withRejecter:)
176
+ func setToken(provider: NSString, token: NSString, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
177
+
178
+ let provider = provider as String
179
+ let token = token as String
180
+
181
+ Task {
182
+ do {
183
+ try await Courier.shared.setToken(
184
+ for: provider,
185
+ token: token
186
+ )
187
+ resolve(nil)
188
+ } catch {
189
+ Rejections.sharedError(reject, error: error)
190
+ }
191
+ }
192
+
193
+ }
194
+
195
+ // MARK: Inbox
196
+
197
+ @objc func getInboxPaginationLimit() -> String {
198
+ return String(describing: Courier.shared.inboxPaginationLimit)
199
+ }
200
+
201
+ @objc(setInboxPaginationLimit:)
202
+ func setInboxPaginationLimit(limit: Double) -> String {
203
+ Courier.shared.inboxPaginationLimit = Int(limit)
204
+ return String(describing: Courier.shared.inboxPaginationLimit)
205
+ }
206
+
207
+ @objc(openMessage:withResolver:withRejecter:)
208
+ func openMessage(messageId: NSString, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
209
+
210
+ let id = messageId as String
211
+
212
+ Task {
213
+ do {
214
+ try await Courier.shared.openMessage(id)
215
+ resolve(nil)
216
+ } catch {
217
+ Rejections.sharedError(reject, error: error)
218
+ }
219
+ }
220
+
221
+ }
222
+
223
+ @objc(archiveMessage:withResolver:withRejecter:)
224
+ func archiveMessage(messageId: NSString, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
225
+
226
+ let id = messageId as String
227
+
228
+ Task {
229
+ do {
230
+ try await Courier.shared.archiveMessage(id)
231
+ resolve(nil)
232
+ } catch {
233
+ Rejections.sharedError(reject, error: error)
234
+ }
235
+ }
236
+
237
+ }
238
+
239
+ @objc(clickMessage:withResolver:withRejecter:)
240
+ func clickMessage(messageId: NSString, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
241
+
242
+ let id = messageId as String
243
+
244
+ Task {
245
+ do {
246
+ try await Courier.shared.clickMessage(id)
247
+ resolve(nil)
248
+ } catch {
249
+ Rejections.sharedError(reject, error: error)
250
+ }
251
+ }
252
+
253
+ }
254
+
255
+ @objc(readMessage:withResolver:withRejecter:)
256
+ func readMessage(messageId: NSString, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
257
+
258
+ let id = messageId as String
259
+
260
+ Task {
261
+ do {
262
+ try await Courier.shared.readMessage(id)
263
+ resolve(nil)
264
+ } catch {
265
+ Rejections.sharedError(reject, error: error)
266
+ }
267
+ }
268
+
269
+ }
270
+
271
+ @objc(unreadMessage:withResolver:withRejecter:)
272
+ func unreadMessage(messageId: NSString, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
273
+
274
+ let id = messageId as String
275
+
276
+ Task {
277
+ do {
278
+ try await Courier.shared.unreadMessage(id)
279
+ resolve(nil)
280
+ } catch {
281
+ Rejections.sharedError(reject, error: error)
282
+ }
283
+ }
284
+
285
+ }
286
+
287
+ @objc(readAllInboxMessages:withRejecter:)
288
+ func readAllInboxMessages(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
289
+
290
+ Task {
291
+ do {
292
+ try await Courier.shared.readAllInboxMessages()
293
+ resolve(nil)
294
+ } catch {
295
+ Rejections.sharedError(reject, error: error)
296
+ }
297
+ }
298
+
299
+ }
300
+
301
+ @objc(addInboxListener: withErrorId: withMessagesId:)
302
+ func addInboxListener(loadingId: String, errorId: String, messagesId: String) -> String {
303
+
304
+ // Add the events
305
+ nativeEmitters.append(contentsOf: [loadingId, errorId, messagesId])
306
+
307
+ // Create the new listener
308
+ let listener = Courier.shared.addInboxListener(
309
+ onInitialLoad: { [weak self] in
310
+ self?.broadcast(
311
+ name: loadingId,
312
+ body: nil
313
+ )
314
+ },
315
+ onError: { [weak self] error in
316
+ self?.broadcast(
317
+ name: errorId,
318
+ body: String(describing: error)
319
+ )
320
+ },
321
+ onMessagesChanged: { [weak self] messages, unreadMessageCount, totalMessageCount, canPaginate in
322
+
323
+ do {
324
+
325
+ let json: [String: Any] = [
326
+ "messages": try messages.map { try $0.toJson() ?? "" },
327
+ "unreadMessageCount": unreadMessageCount,
328
+ "totalMessageCount": totalMessageCount,
329
+ "canPaginate": canPaginate
330
+ ]
331
+
332
+ self?.broadcast(
333
+ name: messagesId,
334
+ body: json
335
+ )
336
+
337
+ } catch {
338
+
339
+ Courier.shared.client?.error(error.localizedDescription)
340
+
341
+ }
342
+
343
+ }
344
+ )
345
+
346
+ let id = UUID().uuidString
347
+ inboxListeners[id] = listener
348
+
349
+ return id
350
+
351
+ }
352
+
353
+ @objc(removeInboxListener:)
354
+ func removeInboxListener(listenerId: NSString) -> String {
355
+
356
+ let id = listenerId as String
357
+
358
+ let listener = inboxListeners[id]
359
+
360
+ // Disable the listener
361
+ listener?.remove()
362
+
363
+ // Remove the id from the map
364
+ inboxListeners.removeValue(forKey: id)
365
+
366
+ return id
367
+
368
+ }
369
+
370
+ @discardableResult @objc func removeAllInboxListeners() -> String? {
371
+
372
+ for value in inboxListeners.values {
373
+ value.remove()
374
+ }
375
+
376
+ inboxListeners.removeAll()
377
+
378
+ return nil
379
+
380
+ }
381
+
382
+ @objc(refreshInbox: withRejecter:)
383
+ func refreshInbox(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
384
+
385
+ Task {
386
+ await Courier.shared.refreshInbox()
387
+ resolve(nil)
388
+ }
389
+
390
+ }
391
+
392
+ @objc(fetchNextPageOfMessages: withRejecter:)
393
+ func fetchNextPageOfMessages(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
394
+
395
+ Task {
396
+
397
+ do {
398
+ let messages = try await Courier.shared.fetchNextInboxPage()
399
+ resolve(try messages.map { try $0.toJson() ?? "" })
400
+ } catch {
401
+ Rejections.sharedError(reject, error: error)
402
+ }
403
+
404
+ }
405
+
406
+ }
407
+
408
+ override func supportedEvents() -> [String]! {
409
+ return nativeEmitters
410
+ }
411
+
412
+ }