@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
@@ -0,0 +1,24 @@
1
+ export interface CourierBrandResponse {
2
+ data?: CourierBrandData
3
+ }
4
+
5
+ export interface CourierBrandData {
6
+ brand?: CourierBrand
7
+ }
8
+
9
+ export interface CourierBrand {
10
+ settings?: CourierBrandSettings
11
+ }
12
+
13
+ export interface CourierBrandSettings {
14
+ inapp?: CourierBrandInApp
15
+ colors?: CourierBrandColors
16
+ }
17
+
18
+ export interface CourierBrandInApp {
19
+ disableCourierFooter?: boolean;
20
+ }
21
+
22
+ export interface CourierBrandColors {
23
+ primary?: string;
24
+ }
@@ -0,0 +1,8 @@
1
+ export interface CourierDevice {
2
+ appId?: string;
3
+ adId?: string;
4
+ deviceId?: string;
5
+ platform?: string;
6
+ manufacturer?: string;
7
+ model?: string;
8
+ }
@@ -1,4 +1,4 @@
1
- import Courier from "@trycourier/courier-react-native";
1
+ import Courier from "..";
2
2
  import { EmitterSubscription } from "react-native";
3
3
 
4
4
  export class CourierInboxListener {
@@ -0,0 +1,28 @@
1
+ import { InboxMessage } from "./InboxMessage";
2
+
3
+ export interface CourierGetInboxMessagesResponse {
4
+ data?: GetInboxMessagesData;
5
+ }
6
+
7
+ export interface GetInboxMessagesData {
8
+ count?: number;
9
+ messages?: GetInboxMessagesNodes;
10
+ }
11
+
12
+ export interface GetInboxMessagesNodes {
13
+ pageInfo?: GetInboxMessagesPageInfo;
14
+ nodes?: InboxMessage[];
15
+ }
16
+
17
+ export interface GetInboxMessagesPageInfo {
18
+ startCursor?: string;
19
+ hasNextPage?: boolean;
20
+ }
21
+
22
+ export interface CourierGetInboxMessageResponse {
23
+ data?: GetInboxMessageData;
24
+ }
25
+
26
+ export interface GetInboxMessageData {
27
+ message: InboxMessage;
28
+ }
@@ -1,13 +1,18 @@
1
- import { EmitterSubscription } from "react-native";
2
-
3
1
  export class CourierPushListener {
4
2
 
5
- public onNotificationClickedListener?: EmitterSubscription
6
- public onNotificationDeliveredListener?: EmitterSubscription
3
+ readonly listenerId: string
4
+ public onPushNotificationClicked?: (push: any) => void
5
+ public onPushNotificationDelivered?: (push: any) => void
6
+
7
+ constructor(id: string, onPushNotificationClicked?: (push: any) => void, onPushNotificationDelivered?: (push: any) => void) {
8
+ this.listenerId = id;
9
+ this.onPushNotificationClicked = onPushNotificationClicked;
10
+ this.onPushNotificationDelivered = onPushNotificationDelivered;
11
+ }
7
12
 
8
13
  public remove() {
9
- this.onNotificationClickedListener?.remove();
10
- this.onNotificationDeliveredListener?.remove();
14
+ this.onPushNotificationClicked = undefined;
15
+ this.onPushNotificationDelivered = undefined;
11
16
  }
12
17
 
13
18
  }
@@ -0,0 +1,7 @@
1
+ export enum CourierTrackingEvent {
2
+ Clicked = "CLICKED",
3
+ Delivered = "DELIVERED",
4
+ Opened = "OPENED",
5
+ Read = "READ",
6
+ Unread = "UNREAD",
7
+ }
@@ -1,7 +1,74 @@
1
1
  import { CourierPaging } from "./CourierPaging";
2
- import { CourierUserPreferencesTopic } from "./CourierUserPreferencesTopic";
3
2
 
4
3
  export interface CourierUserPreferences {
5
- items?: CourierUserPreferencesTopic[];
6
- paging?: CourierPaging;
4
+ items: CourierUserPreferencesTopic[];
5
+ paging: CourierPaging;
6
+ }
7
+
8
+ export interface CourierUserPreferencesTopic {
9
+ defaultStatus: CourierUserPreferencesStatus;
10
+ hasCustomRouting: boolean;
11
+ customRouting: CourierUserPreferencesChannel[];
12
+ status: CourierUserPreferencesStatus;
13
+ topicId: string;
14
+ topicName: string;
15
+ sectionName: string;
16
+ sectionId: string;
17
+ }
18
+
19
+ export interface GetCourierUserPreferencesTopic {
20
+ topic: CourierUserPreferencesTopic;
21
+ }
22
+
23
+ // Additional interfaces for CourierUserPreferencesStatus and CourierUserPreferencesChannel would be needed based on their definitions
24
+ export enum CourierUserPreferencesStatus {
25
+ OptedIn = "OPTED_IN",
26
+ OptedOut = "OPTED_OUT",
27
+ Required = "REQUIRED",
28
+ Unknown = "UNKNOWN",
29
+ }
30
+
31
+ // Function to get the title of the enum value
32
+ export function getCourierUserPreferencesStatusTitle(status: CourierUserPreferencesStatus): string {
33
+ switch (status) {
34
+ case CourierUserPreferencesStatus.OptedIn:
35
+ return "Opted In";
36
+ case CourierUserPreferencesStatus.OptedOut:
37
+ return "Opted Out";
38
+ case CourierUserPreferencesStatus.Required:
39
+ return "Required";
40
+ case CourierUserPreferencesStatus.Unknown:
41
+ return "Unknown";
42
+ default:
43
+ return "Unknown";
44
+ }
45
+ }
46
+
47
+ export enum CourierUserPreferencesChannel {
48
+ DirectMessage = "direct_message",
49
+ Email = "email",
50
+ Push = "push",
51
+ Sms = "sms",
52
+ Webhook = "webhook",
53
+ Unknown = "unknown",
54
+ }
55
+
56
+ // Function to get the title of the enum value
57
+ export function getCourierUserPreferencesChannelTitle(channel: CourierUserPreferencesChannel): string {
58
+ switch (channel) {
59
+ case CourierUserPreferencesChannel.DirectMessage:
60
+ return "In App Messages";
61
+ case CourierUserPreferencesChannel.Email:
62
+ return "Emails";
63
+ case CourierUserPreferencesChannel.Push:
64
+ return "Push Notifications";
65
+ case CourierUserPreferencesChannel.Sms:
66
+ return "Text Messages";
67
+ case CourierUserPreferencesChannel.Webhook:
68
+ return "Webhooks";
69
+ case CourierUserPreferencesChannel.Unknown:
70
+ return "Unknown";
71
+ default:
72
+ return "Unknown";
73
+ }
7
74
  }
package/src/utils.tsx CHANGED
@@ -1,4 +1,4 @@
1
- import { EmitterSubscription, Platform, DeviceEventEmitter, NativeEventEmitter } from "react-native";
1
+ import packageJson from '../package.json';
2
2
 
3
3
  export namespace Events {
4
4
 
@@ -13,29 +13,9 @@ export namespace Events {
13
13
 
14
14
  }
15
15
 
16
- export namespace Utils {
16
+ export class Utils {
17
17
 
18
- /**
19
- * Creates an event listener for the native function
20
- * @param key Key for the listener
21
- * @param callback Value returned for the listener callback
22
- * @returns Subscription
23
- */
24
- export function addEventListener(key: string, emitter: NativeEventEmitter, callback: (value: any) => void): EmitterSubscription | undefined {
25
-
26
- if (Platform.OS === 'android') {
27
- return DeviceEventEmitter.addListener(key, (event: any) => callback(event));
28
- }
29
-
30
- if (Platform.OS === 'ios') {
31
- return emitter.addListener(key, (event: any) => callback(event));
32
- }
33
-
34
- return undefined;
35
-
36
- }
37
-
38
- export function generateUUID(): string {
18
+ static generateUUID(): string {
39
19
  let uuid = '';
40
20
  const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
41
21
  const charactersLength = characters.length;
@@ -45,4 +25,8 @@ export namespace Utils {
45
25
  return uuid;
46
26
  }
47
27
 
28
+ static getPackageVersion(): string {
29
+ return packageJson.version;
30
+ }
31
+
48
32
  }
@@ -62,7 +62,7 @@ export const CourierInboxView = (props: CourierInboxViewProps) => {
62
62
  if (props.onClickInboxMessageAtIndex) {
63
63
 
64
64
  const index = event["index"];
65
- const message = event["message"] as InboxMessage;
65
+ const message = JSON.parse(event["message"]) as InboxMessage;
66
66
 
67
67
  props.onClickInboxMessageAtIndex(message, index);
68
68
 
@@ -86,8 +86,8 @@ export const CourierInboxView = (props: CourierInboxViewProps) => {
86
86
  if (props.onClickInboxActionForMessageAtIndex) {
87
87
 
88
88
  const index = event["index"];
89
- const action = event["action"] as InboxAction;
90
- const message = event["message"] as InboxMessage;
89
+ const action = JSON.parse(event["action"]) as InboxAction;
90
+ const message = JSON.parse(event["message"]) as InboxMessage;
91
91
 
92
92
  props.onClickInboxActionForMessageAtIndex(action, message, index);
93
93
 
@@ -1,393 +0,0 @@
1
- package com.courierreactnative
2
-
3
- import android.content.Intent
4
- import com.courier.android.Courier
5
- import com.courier.android.models.CourierAgent
6
- import com.courier.android.models.CourierAuthenticationListener
7
- import com.courier.android.models.CourierInboxListener
8
- import com.courier.android.models.CourierPreferenceChannel
9
- import com.courier.android.models.CourierPreferenceStatus
10
- import com.courier.android.models.InboxMessage
11
- import com.courier.android.models.remove
12
- import com.courier.android.modules.addAuthenticationListener
13
- import com.courier.android.modules.addInboxListener
14
- import com.courier.android.modules.clickMessage
15
- import com.courier.android.modules.fetchNextPageOfMessages
16
- import com.courier.android.modules.getToken
17
- import com.courier.android.modules.getUserPreferenceTopic
18
- import com.courier.android.modules.getUserPreferences
19
- import com.courier.android.modules.inboxPaginationLimit
20
- import com.courier.android.modules.isDebugging
21
- import com.courier.android.modules.isPushPermissionGranted
22
- import com.courier.android.modules.logListener
23
- import com.courier.android.modules.putUserPreferenceTopic
24
- import com.courier.android.modules.readAllInboxMessages
25
- import com.courier.android.modules.readMessage
26
- import com.courier.android.modules.refreshInbox
27
- import com.courier.android.modules.requestNotificationPermission
28
- import com.courier.android.modules.setToken
29
- import com.courier.android.modules.signIn
30
- import com.courier.android.modules.signOut
31
- import com.courier.android.modules.tenantId
32
- import com.courier.android.modules.unreadMessage
33
- import com.courier.android.modules.userId
34
- import com.courier.android.utils.pushNotification
35
- import com.courier.android.utils.trackPushNotificationClick
36
- import com.facebook.react.ReactActivity
37
- import com.facebook.react.bridge.Arguments
38
- import com.facebook.react.bridge.Promise
39
- import com.facebook.react.bridge.ReactApplicationContext
40
- import com.facebook.react.bridge.ReactContextBaseJavaModule
41
- import com.facebook.react.bridge.ReactMethod
42
- import com.facebook.react.bridge.ReadableArray
43
- import com.google.firebase.messaging.RemoteMessage
44
- import org.json.JSONObject
45
- import java.util.UUID
46
-
47
-
48
- class CourierReactNativeModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
49
-
50
- override fun getName() = "CourierReactNativeModule"
51
- private val reactActivity: ReactActivity? get() = currentActivity as? ReactActivity
52
-
53
- // Listeners
54
- private var authListeners = mutableMapOf<String, CourierAuthenticationListener>()
55
- private var inboxListeners = mutableMapOf<String, CourierInboxListener>()
56
-
57
- init {
58
-
59
- // User Agent is used to ensure we know the SDK
60
- // the requests come from
61
- Courier.USER_AGENT = CourierAgent.REACT_NATIVE_ANDROID
62
-
63
- // Attach the log listener
64
- Courier.shared.logListener = { data ->
65
- reactContext.sendEvent(CourierEvents.Log.DEBUG_LOG, data)
66
- }
67
-
68
- }
69
-
70
- @ReactMethod
71
- fun addListener(type: String?) {
72
- // Keep: Required for RN built in Event Emitter Calls.
73
- }
74
-
75
- @ReactMethod
76
- fun removeListeners(type: Int?) {
77
- // Keep: Required for RN built in Event Emitter Calls.
78
- }
79
-
80
- @ReactMethod(isBlockingSynchronousMethod = true)
81
- fun setDebugMode(isDebugging: Boolean): Boolean {
82
- Courier.shared.isDebugging = isDebugging
83
- return Courier.shared.isDebugging
84
- }
85
-
86
- @ReactMethod
87
- fun registerPushNotificationClickedOnKilledState() {
88
- reactActivity?.let { activity ->
89
- checkIntentForPushNotificationClick(activity.intent)
90
- }
91
- }
92
-
93
- private fun checkIntentForPushNotificationClick(intent: Intent?) {
94
- intent?.trackPushNotificationClick { message ->
95
- postPushNotificationClicked(message)
96
- }
97
- }
98
-
99
- private fun postPushNotificationClicked(message: RemoteMessage) {
100
- reactApplicationContext.sendEvent(
101
- eventName = CourierEvents.Push.CLICKED_EVENT,
102
- value = JSONObject(message.pushNotification).toString()
103
- )
104
- }
105
-
106
- @ReactMethod
107
- fun requestNotificationPermission(promise: Promise) {
108
-
109
- reactActivity?.let { activity ->
110
- Courier.shared.requestNotificationPermission(activity)
111
- }
112
-
113
- promise.resolve("unknown")
114
-
115
- }
116
-
117
- @ReactMethod
118
- fun getNotificationPermissionStatus(promise: Promise) {
119
-
120
- reactActivity?.let { context ->
121
-
122
- val isGranted = Courier.shared.isPushPermissionGranted(context)
123
- val status = if (isGranted) "authorized" else "denied"
124
- promise.resolve(status)
125
- return
126
-
127
- }
128
-
129
- promise.resolve("unknown")
130
-
131
- }
132
-
133
- @ReactMethod
134
- fun signIn(accessToken: String, clientKey: String?, userId: String, tenantId: String?, promise: Promise) {
135
- Courier.shared.signIn(
136
- accessToken = accessToken,
137
- clientKey = clientKey,
138
- userId = userId,
139
- tenantId = tenantId,
140
- onSuccess = {
141
- promise.resolve(null)
142
- },
143
- onFailure = { e ->
144
- promise.reject(CourierEvents.COURIER_ERROR_TAG, e)
145
- }
146
- )
147
- }
148
-
149
- @ReactMethod
150
- fun signOut(promise: Promise) {
151
- Courier.shared.signOut(
152
- onSuccess = {
153
- promise.resolve(null)
154
- },
155
- onFailure = { e ->
156
- promise.reject(CourierEvents.COURIER_ERROR_TAG, e)
157
- }
158
- )
159
- }
160
-
161
- @ReactMethod(isBlockingSynchronousMethod = true)
162
- fun getUserId(): String? {
163
- return Courier.shared.userId
164
- }
165
-
166
- @ReactMethod(isBlockingSynchronousMethod = true)
167
- fun getTenantId(): String? {
168
- return Courier.shared.tenantId
169
- }
170
-
171
- @ReactMethod(isBlockingSynchronousMethod = true)
172
- fun addAuthenticationListener(authId: String): String {
173
-
174
- // Create the listener
175
- val listener = Courier.shared.addAuthenticationListener { userId ->
176
-
177
- reactApplicationContext.sendEvent(
178
- eventName = authId,
179
- value = userId
180
- )
181
-
182
- }
183
-
184
- // Add the listener to the map
185
- val id = UUID.randomUUID().toString()
186
- authListeners[id] = listener
187
-
188
- return id
189
-
190
- }
191
-
192
- @ReactMethod(isBlockingSynchronousMethod = true)
193
- fun removeAuthenticationListener(listenerId: String): String {
194
-
195
- // Get the listener
196
- val listener = authListeners[listenerId]
197
-
198
- // Remove the listener
199
- listener?.remove()
200
-
201
- // Remove the listener
202
- authListeners.remove(listenerId)
203
-
204
- return listenerId
205
-
206
- }
207
-
208
- @ReactMethod
209
- fun getToken(key: String, promise: Promise) {
210
- val token = Courier.shared.getToken(key)
211
- promise.resolve(token)
212
- }
213
-
214
- @ReactMethod
215
- fun setToken(key: String, token: String, promise: Promise) {
216
- Courier.shared.setToken(
217
- provider = key,
218
- token = token,
219
- onSuccess = {
220
- promise.resolve(null)
221
- },
222
- onFailure = { e ->
223
- promise.reject(CourierEvents.COURIER_ERROR_TAG, e)
224
- }
225
- )
226
- }
227
-
228
- @ReactMethod(isBlockingSynchronousMethod = true)
229
- fun clickMessage(messageId: String): String {
230
- Courier.shared.clickMessage(messageId, onFailure = null)
231
- return messageId
232
- }
233
-
234
- @ReactMethod(isBlockingSynchronousMethod = true)
235
- fun readMessage(messageId: String): String {
236
- Courier.shared.readMessage(messageId, onFailure = null)
237
- return messageId
238
- }
239
-
240
- @ReactMethod(isBlockingSynchronousMethod = true)
241
- fun unreadMessage(messageId: String): String {
242
- Courier.shared.unreadMessage(messageId, onFailure = null)
243
- return messageId
244
- }
245
-
246
- @ReactMethod
247
- fun readAllInboxMessages(promise: Promise) {
248
- Courier.shared.readAllInboxMessages(
249
- onSuccess = {
250
- promise.resolve(null)
251
- },
252
- onFailure = { e ->
253
- promise.reject(CourierEvents.COURIER_ERROR_TAG, e)
254
- }
255
- )
256
- }
257
-
258
- @ReactMethod(isBlockingSynchronousMethod = true)
259
- fun addInboxListener(loadingId: String, errorId: String, messagesId: String): String {
260
-
261
- val listener = Courier.shared.addInboxListener(
262
- onInitialLoad = {
263
-
264
- reactApplicationContext.sendEvent(
265
- eventName = loadingId,
266
- value = null
267
- )
268
-
269
- },
270
- onError = { e ->
271
-
272
- reactApplicationContext.sendEvent(
273
- eventName = errorId,
274
- value = e.message ?: "Courier Inbox Error"
275
- )
276
-
277
- },
278
- onMessagesChanged = { messages: List<InboxMessage>, unreadMessageCount: Int, totalMessageCount: Int, canPaginate: Boolean ->
279
-
280
- val json = Arguments.createMap()
281
- json.putArray("messages", messages.toList().toWritableArray())
282
- json.putInt("unreadMessageCount", unreadMessageCount)
283
- json.putInt("totalMessageCount", totalMessageCount)
284
- json.putBoolean("canPaginate", canPaginate)
285
-
286
- reactApplicationContext.sendEvent(
287
- eventName = messagesId,
288
- value = json
289
- )
290
-
291
- }
292
- )
293
-
294
- // Add listener
295
- val id = UUID.randomUUID().toString()
296
- inboxListeners[id] = listener
297
-
298
- return id
299
-
300
- }
301
-
302
- @ReactMethod(isBlockingSynchronousMethod = true)
303
- fun removeInboxListener(listenerId: String): String {
304
-
305
- // Get the listener
306
- val listener = inboxListeners[listenerId]
307
-
308
- // Remove the listener
309
- listener?.remove()
310
-
311
- // Remove the listener
312
- inboxListeners.remove(listenerId)
313
-
314
- return listenerId
315
-
316
- }
317
-
318
- @ReactMethod
319
- fun refreshInbox(promise: Promise) {
320
- Courier.shared.refreshInbox {
321
- promise.resolve(null)
322
- }
323
- }
324
-
325
- @ReactMethod
326
- fun fetchNextPageOfMessages(promise: Promise) {
327
- Courier.shared.fetchNextPageOfMessages(
328
- onSuccess = { messages ->
329
- promise.resolve(messages.toWritableArray())
330
- },
331
- onFailure = { e ->
332
- promise.reject(CourierEvents.COURIER_ERROR_TAG, e)
333
- }
334
- )
335
- }
336
-
337
- @ReactMethod(isBlockingSynchronousMethod = true)
338
- fun setInboxPaginationLimit(limit: Double): String {
339
- Courier.shared.inboxPaginationLimit = limit.toInt()
340
- return Courier.shared.inboxPaginationLimit.toString()
341
- }
342
-
343
- @ReactMethod
344
- fun getUserPreferences(paginationCursor: String, promise: Promise) {
345
-
346
- val cursor = if (paginationCursor != "") paginationCursor else null
347
-
348
- Courier.shared.getUserPreferences(
349
- paginationCursor = cursor,
350
- onSuccess = { preferences ->
351
- promise.resolve(preferences.toWritableMap())
352
- },
353
- onFailure = { e ->
354
- promise.reject(CourierEvents.COURIER_ERROR_TAG, e)
355
- }
356
- )
357
-
358
- }
359
-
360
- @ReactMethod
361
- fun getUserPreferencesTopic(topicId: String, promise: Promise) {
362
- Courier.shared.getUserPreferenceTopic(
363
- topicId = topicId,
364
- onSuccess = { topic ->
365
- promise.resolve(topic.toWritableMap())
366
- },
367
- onFailure = { e ->
368
- promise.reject(CourierEvents.COURIER_ERROR_TAG, e)
369
- }
370
- )
371
- }
372
-
373
- @ReactMethod
374
- fun putUserPreferencesTopic(topicId: String, status: String, hasCustomRouting: Boolean, customRouting: ReadableArray, promise: Promise) {
375
-
376
- val routing = customRouting.toArrayList().map { CourierPreferenceChannel.fromString(it as String) }
377
-
378
- Courier.shared.putUserPreferenceTopic(
379
- topicId = topicId,
380
- status = CourierPreferenceStatus.fromString(status),
381
- hasCustomRouting = hasCustomRouting,
382
- customRouting = routing,
383
- onSuccess = {
384
- promise.resolve(null)
385
- },
386
- onFailure = { e ->
387
- promise.reject(CourierEvents.COURIER_ERROR_TAG, e)
388
- }
389
- )
390
-
391
- }
392
-
393
- }