@trycourier/courier-react-native 3.2.1 → 4.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (251) hide show
  1. package/android/build.gradle +4 -1
  2. package/android/src/main/java/com/courierreactnative/CourierClientModule.kt +441 -0
  3. package/android/src/main/java/com/courierreactnative/CourierInboxViewManager.kt +2 -2
  4. package/android/src/main/java/com/courierreactnative/CourierReactNativePackage.kt +9 -3
  5. package/android/src/main/java/com/courierreactnative/CourierSharedModule.kt +321 -0
  6. package/android/src/main/java/com/courierreactnative/CourierSystemModule.kt +91 -0
  7. package/android/src/main/java/com/courierreactnative/ReactNativeModule.kt +36 -0
  8. package/android/src/main/java/com/courierreactnative/{Extensions.kt → Utils.kt} +5 -5
  9. package/courier-react-native.podspec +1 -1
  10. package/ios/CourierClientModule.swift +450 -0
  11. package/ios/CourierInboxReactNativeManager.swift +17 -9
  12. package/ios/CourierReactNativeDelegate.m +18 -35
  13. package/ios/CourierReactNativeEventEmitter.swift +25 -0
  14. package/ios/CourierReactNativeModule.m +192 -23
  15. package/ios/CourierSharedModule.swift +425 -0
  16. package/ios/CourierSystemModule.swift +147 -0
  17. package/ios/Utils.swift +103 -115
  18. package/lib/commonjs/Broadcaster.js +30 -0
  19. package/lib/commonjs/Broadcaster.js.map +1 -0
  20. package/lib/commonjs/Modules.js +25 -0
  21. package/lib/commonjs/Modules.js.map +1 -0
  22. package/lib/commonjs/client/BrandClient.js +25 -0
  23. package/lib/commonjs/client/BrandClient.js.map +1 -0
  24. package/lib/commonjs/client/ClientModule.js +21 -0
  25. package/lib/commonjs/client/ClientModule.js.map +1 -0
  26. package/lib/commonjs/client/CourierClient.js +33 -0
  27. package/lib/commonjs/client/CourierClient.js.map +1 -0
  28. package/lib/commonjs/client/InboxClient.js +116 -0
  29. package/lib/commonjs/client/InboxClient.js.map +1 -0
  30. package/lib/commonjs/client/PreferenceClient.js +73 -0
  31. package/lib/commonjs/client/PreferenceClient.js.map +1 -0
  32. package/lib/commonjs/client/TokenClient.js +36 -0
  33. package/lib/commonjs/client/TokenClient.js.map +1 -0
  34. package/lib/commonjs/client/TrackingClient.js +25 -0
  35. package/lib/commonjs/client/TrackingClient.js.map +1 -0
  36. package/lib/commonjs/index.js +418 -186
  37. package/lib/commonjs/index.js.map +1 -1
  38. package/lib/commonjs/models/Android_CourierSheet.js.map +1 -1
  39. package/lib/commonjs/models/CourierAuthenticationListener.js.map +1 -1
  40. package/lib/commonjs/models/CourierBrand.js +2 -0
  41. package/lib/commonjs/models/{CourierUserPreferencesTopic.js.map → CourierBrand.js.map} +1 -1
  42. package/lib/commonjs/models/CourierButton.js.map +1 -1
  43. package/lib/commonjs/models/CourierDevice.js +2 -0
  44. package/lib/commonjs/models/CourierDevice.js.map +1 -0
  45. package/lib/commonjs/models/CourierFont.js.map +1 -1
  46. package/lib/commonjs/models/CourierInboxListener.js +2 -2
  47. package/lib/commonjs/models/CourierInboxListener.js.map +1 -1
  48. package/lib/commonjs/models/{CourierUserPreferencesTopic.js → CourierInboxMessages.js} +1 -1
  49. package/lib/commonjs/models/CourierInboxMessages.js.map +1 -0
  50. package/lib/commonjs/models/CourierInboxTheme.js.map +1 -1
  51. package/lib/commonjs/models/CourierInfoViewStyle.js.map +1 -1
  52. package/lib/commonjs/models/CourierPaging.js.map +1 -1
  53. package/lib/commonjs/models/CourierPreferencesTheme.js.map +1 -1
  54. package/lib/commonjs/models/CourierPushListener.js +7 -3
  55. package/lib/commonjs/models/CourierPushListener.js.map +1 -1
  56. package/lib/commonjs/models/CourierPushProvider.js.map +1 -1
  57. package/lib/commonjs/models/CourierTrackingEvent.js +16 -0
  58. package/lib/commonjs/models/CourierTrackingEvent.js.map +1 -0
  59. package/lib/commonjs/models/CourierUserPreferences.js +54 -0
  60. package/lib/commonjs/models/CourierUserPreferences.js.map +1 -1
  61. package/lib/commonjs/models/InboxAction.js.map +1 -1
  62. package/lib/commonjs/models/InboxMessage.js.map +1 -1
  63. package/lib/commonjs/models/iOS_CourierCell.js.map +1 -1
  64. package/lib/commonjs/models/iOS_CourierSheet.js.map +1 -1
  65. package/lib/commonjs/utils.js +9 -17
  66. package/lib/commonjs/utils.js.map +1 -1
  67. package/lib/commonjs/views/CourierInboxView.js +3 -3
  68. package/lib/commonjs/views/CourierInboxView.js.map +1 -1
  69. package/lib/commonjs/views/CourierPreferencesView.js.map +1 -1
  70. package/lib/module/Broadcaster.js +23 -0
  71. package/lib/module/Broadcaster.js.map +1 -0
  72. package/lib/module/Modules.js +18 -0
  73. package/lib/module/Modules.js.map +1 -0
  74. package/lib/module/client/BrandClient.js +18 -0
  75. package/lib/module/client/BrandClient.js.map +1 -0
  76. package/lib/module/client/ClientModule.js +14 -0
  77. package/lib/module/client/ClientModule.js.map +1 -0
  78. package/lib/module/client/CourierClient.js +26 -0
  79. package/lib/module/client/CourierClient.js.map +1 -0
  80. package/lib/module/client/InboxClient.js +109 -0
  81. package/lib/module/client/InboxClient.js.map +1 -0
  82. package/lib/module/client/PreferenceClient.js +66 -0
  83. package/lib/module/client/PreferenceClient.js.map +1 -0
  84. package/lib/module/client/TokenClient.js +29 -0
  85. package/lib/module/client/TokenClient.js.map +1 -0
  86. package/lib/module/client/TrackingClient.js +18 -0
  87. package/lib/module/client/TrackingClient.js.map +1 -0
  88. package/lib/module/index.js +383 -185
  89. package/lib/module/index.js.map +1 -1
  90. package/lib/module/models/Android_CourierSheet.js.map +1 -1
  91. package/lib/module/models/CourierAuthenticationListener.js.map +1 -1
  92. package/lib/module/models/CourierBrand.js +2 -0
  93. package/lib/module/models/{CourierUserPreferencesTopic.js.map → CourierBrand.js.map} +1 -1
  94. package/lib/module/models/CourierButton.js.map +1 -1
  95. package/lib/module/models/CourierDevice.js +2 -0
  96. package/lib/module/models/CourierDevice.js.map +1 -0
  97. package/lib/module/models/CourierFont.js.map +1 -1
  98. package/lib/module/models/CourierInboxListener.js +1 -1
  99. package/lib/module/models/CourierInboxListener.js.map +1 -1
  100. package/lib/module/models/CourierInboxMessages.js +2 -0
  101. package/lib/module/models/CourierInboxMessages.js.map +1 -0
  102. package/lib/module/models/CourierInboxTheme.js.map +1 -1
  103. package/lib/module/models/CourierInfoViewStyle.js.map +1 -1
  104. package/lib/module/models/CourierPaging.js.map +1 -1
  105. package/lib/module/models/CourierPreferencesTheme.js.map +1 -1
  106. package/lib/module/models/CourierPushListener.js +7 -3
  107. package/lib/module/models/CourierPushListener.js.map +1 -1
  108. package/lib/module/models/CourierPushProvider.js.map +1 -1
  109. package/lib/module/models/CourierTrackingEvent.js +9 -0
  110. package/lib/module/models/CourierTrackingEvent.js.map +1 -0
  111. package/lib/module/models/CourierUserPreferences.js +53 -1
  112. package/lib/module/models/CourierUserPreferences.js.map +1 -1
  113. package/lib/module/models/InboxAction.js.map +1 -1
  114. package/lib/module/models/InboxMessage.js.map +1 -1
  115. package/lib/module/models/iOS_CourierCell.js.map +1 -1
  116. package/lib/module/models/iOS_CourierSheet.js.map +1 -1
  117. package/lib/module/utils.js +7 -16
  118. package/lib/module/utils.js.map +1 -1
  119. package/lib/module/views/CourierInboxView.js +3 -3
  120. package/lib/module/views/CourierInboxView.js.map +1 -1
  121. package/lib/module/views/CourierPreferencesView.js.map +1 -1
  122. package/lib/typescript/src/Broadcaster.d.ts +14 -0
  123. package/lib/typescript/src/Broadcaster.d.ts.map +1 -0
  124. package/lib/typescript/src/Modules.d.ts +8 -0
  125. package/lib/typescript/src/Modules.d.ts.map +1 -0
  126. package/lib/typescript/src/client/BrandClient.d.ts +15 -0
  127. package/lib/typescript/src/client/BrandClient.d.ts.map +1 -0
  128. package/lib/typescript/src/client/ClientModule.d.ts +8 -0
  129. package/lib/typescript/src/client/ClientModule.d.ts.map +1 -0
  130. package/lib/typescript/src/client/CourierClient.d.ts +31 -0
  131. package/lib/typescript/src/client/CourierClient.d.ts.map +1 -0
  132. package/lib/typescript/src/client/InboxClient.d.ts +94 -0
  133. package/lib/typescript/src/client/InboxClient.d.ts.map +1 -0
  134. package/lib/typescript/src/client/PreferenceClient.d.ts +39 -0
  135. package/lib/typescript/src/client/PreferenceClient.d.ts.map +1 -0
  136. package/lib/typescript/src/client/TokenClient.d.ts +28 -0
  137. package/lib/typescript/src/client/TokenClient.d.ts.map +1 -0
  138. package/lib/typescript/src/client/TrackingClient.d.ts +17 -0
  139. package/lib/typescript/src/client/TrackingClient.d.ts.map +1 -0
  140. package/lib/typescript/src/index.d.ts +300 -0
  141. package/lib/typescript/src/index.d.ts.map +1 -0
  142. package/lib/typescript/src/models/Android_CourierSheet.d.ts.map +1 -0
  143. package/lib/typescript/src/models/CourierAuthenticationListener.d.ts.map +1 -0
  144. package/lib/typescript/src/models/CourierBrand.d.ts +20 -0
  145. package/lib/typescript/src/models/CourierBrand.d.ts.map +1 -0
  146. package/lib/typescript/src/models/CourierButton.d.ts.map +1 -0
  147. package/lib/typescript/src/models/CourierDevice.d.ts +9 -0
  148. package/lib/typescript/src/models/CourierDevice.d.ts.map +1 -0
  149. package/lib/typescript/src/models/CourierFont.d.ts.map +1 -0
  150. package/lib/typescript/src/models/CourierInboxListener.d.ts.map +1 -0
  151. package/lib/typescript/src/models/CourierInboxMessages.d.ts +23 -0
  152. package/lib/typescript/src/models/CourierInboxMessages.d.ts.map +1 -0
  153. package/lib/typescript/src/models/CourierInboxTheme.d.ts.map +1 -0
  154. package/lib/typescript/src/models/CourierInfoViewStyle.d.ts.map +1 -0
  155. package/lib/typescript/src/models/CourierPaging.d.ts.map +1 -0
  156. package/lib/typescript/src/models/CourierPreferencesTheme.d.ts.map +1 -0
  157. package/lib/typescript/src/models/CourierPushListener.d.ts +8 -0
  158. package/lib/typescript/src/models/CourierPushListener.d.ts.map +1 -0
  159. package/lib/typescript/src/models/CourierPushProvider.d.ts.map +1 -0
  160. package/lib/typescript/src/models/CourierTrackingEvent.d.ts +8 -0
  161. package/lib/typescript/src/models/CourierTrackingEvent.d.ts.map +1 -0
  162. package/lib/typescript/src/models/CourierUserPreferences.d.ts +35 -0
  163. package/lib/typescript/src/models/CourierUserPreferences.d.ts.map +1 -0
  164. package/lib/typescript/src/models/InboxAction.d.ts.map +1 -0
  165. package/lib/typescript/src/models/InboxMessage.d.ts.map +1 -0
  166. package/lib/typescript/src/models/iOS_CourierCell.d.ts.map +1 -0
  167. package/lib/typescript/src/models/iOS_CourierSheet.d.ts.map +1 -0
  168. package/lib/typescript/src/utils.d.ts +14 -0
  169. package/lib/typescript/src/utils.d.ts.map +1 -0
  170. package/lib/typescript/src/views/CourierInboxView.d.ts.map +1 -0
  171. package/lib/typescript/src/views/CourierPreferencesView.d.ts.map +1 -0
  172. package/package.json +3 -3
  173. package/src/Broadcaster.tsx +32 -0
  174. package/src/Modules.tsx +28 -0
  175. package/src/client/BrandClient.tsx +23 -0
  176. package/src/client/ClientModule.tsx +21 -0
  177. package/src/client/CourierClient.tsx +49 -0
  178. package/src/client/InboxClient.tsx +114 -0
  179. package/src/client/PreferenceClient.tsx +77 -0
  180. package/src/client/TokenClient.tsx +34 -0
  181. package/src/client/TrackingClient.tsx +23 -0
  182. package/src/index.tsx +398 -205
  183. package/src/models/CourierBrand.tsx +24 -0
  184. package/src/models/CourierDevice.tsx +8 -0
  185. package/src/models/CourierInboxListener.tsx +1 -1
  186. package/src/models/CourierInboxMessages.tsx +28 -0
  187. package/src/models/CourierPushListener.tsx +11 -6
  188. package/src/models/CourierTrackingEvent.tsx +7 -0
  189. package/src/models/CourierUserPreferences.tsx +70 -3
  190. package/src/utils.tsx +7 -23
  191. package/src/views/CourierInboxView.tsx +3 -3
  192. package/android/src/main/java/com/courierreactnative/CourierReactNativeModule.kt +0 -393
  193. package/ios/CourierReactNativeModule.swift +0 -524
  194. package/lib/commonjs/models/CourierUserPreferencesChannel.js +0 -17
  195. package/lib/commonjs/models/CourierUserPreferencesChannel.js.map +0 -1
  196. package/lib/commonjs/models/CourierUserPreferencesStatus.js +0 -15
  197. package/lib/commonjs/models/CourierUserPreferencesStatus.js.map +0 -1
  198. package/lib/module/models/CourierUserPreferencesChannel.js +0 -10
  199. package/lib/module/models/CourierUserPreferencesChannel.js.map +0 -1
  200. package/lib/module/models/CourierUserPreferencesStatus.js +0 -8
  201. package/lib/module/models/CourierUserPreferencesStatus.js.map +0 -1
  202. package/lib/module/models/CourierUserPreferencesTopic.js +0 -2
  203. package/lib/typescript/index.d.ts +0 -199
  204. package/lib/typescript/index.d.ts.map +0 -1
  205. package/lib/typescript/models/Android_CourierSheet.d.ts.map +0 -1
  206. package/lib/typescript/models/CourierAuthenticationListener.d.ts.map +0 -1
  207. package/lib/typescript/models/CourierButton.d.ts.map +0 -1
  208. package/lib/typescript/models/CourierFont.d.ts.map +0 -1
  209. package/lib/typescript/models/CourierInboxListener.d.ts.map +0 -1
  210. package/lib/typescript/models/CourierInboxTheme.d.ts.map +0 -1
  211. package/lib/typescript/models/CourierInfoViewStyle.d.ts.map +0 -1
  212. package/lib/typescript/models/CourierPaging.d.ts.map +0 -1
  213. package/lib/typescript/models/CourierPreferencesTheme.d.ts.map +0 -1
  214. package/lib/typescript/models/CourierPushListener.d.ts +0 -7
  215. package/lib/typescript/models/CourierPushListener.d.ts.map +0 -1
  216. package/lib/typescript/models/CourierPushProvider.d.ts.map +0 -1
  217. package/lib/typescript/models/CourierUserPreferences.d.ts +0 -7
  218. package/lib/typescript/models/CourierUserPreferences.d.ts.map +0 -1
  219. package/lib/typescript/models/CourierUserPreferencesChannel.d.ts +0 -9
  220. package/lib/typescript/models/CourierUserPreferencesChannel.d.ts.map +0 -1
  221. package/lib/typescript/models/CourierUserPreferencesStatus.d.ts +0 -7
  222. package/lib/typescript/models/CourierUserPreferencesStatus.d.ts.map +0 -1
  223. package/lib/typescript/models/CourierUserPreferencesTopic.d.ts +0 -13
  224. package/lib/typescript/models/CourierUserPreferencesTopic.d.ts.map +0 -1
  225. package/lib/typescript/models/InboxAction.d.ts.map +0 -1
  226. package/lib/typescript/models/InboxMessage.d.ts.map +0 -1
  227. package/lib/typescript/models/iOS_CourierCell.d.ts.map +0 -1
  228. package/lib/typescript/models/iOS_CourierSheet.d.ts.map +0 -1
  229. package/lib/typescript/utils.d.ts +0 -21
  230. package/lib/typescript/utils.d.ts.map +0 -1
  231. package/lib/typescript/views/CourierInboxView.d.ts.map +0 -1
  232. package/lib/typescript/views/CourierPreferencesView.d.ts.map +0 -1
  233. package/src/models/CourierUserPreferencesChannel.tsx +0 -8
  234. package/src/models/CourierUserPreferencesStatus.tsx +0 -6
  235. package/src/models/CourierUserPreferencesTopic.tsx +0 -13
  236. /package/lib/typescript/{models → src/models}/Android_CourierSheet.d.ts +0 -0
  237. /package/lib/typescript/{models → src/models}/CourierAuthenticationListener.d.ts +0 -0
  238. /package/lib/typescript/{models → src/models}/CourierButton.d.ts +0 -0
  239. /package/lib/typescript/{models → src/models}/CourierFont.d.ts +0 -0
  240. /package/lib/typescript/{models → src/models}/CourierInboxListener.d.ts +0 -0
  241. /package/lib/typescript/{models → src/models}/CourierInboxTheme.d.ts +0 -0
  242. /package/lib/typescript/{models → src/models}/CourierInfoViewStyle.d.ts +0 -0
  243. /package/lib/typescript/{models → src/models}/CourierPaging.d.ts +0 -0
  244. /package/lib/typescript/{models → src/models}/CourierPreferencesTheme.d.ts +0 -0
  245. /package/lib/typescript/{models → src/models}/CourierPushProvider.d.ts +0 -0
  246. /package/lib/typescript/{models → src/models}/InboxAction.d.ts +0 -0
  247. /package/lib/typescript/{models → src/models}/InboxMessage.d.ts +0 -0
  248. /package/lib/typescript/{models → src/models}/iOS_CourierCell.d.ts +0 -0
  249. /package/lib/typescript/{models → src/models}/iOS_CourierSheet.d.ts +0 -0
  250. /package/lib/typescript/{views → src/views}/CourierInboxView.d.ts +0 -0
  251. /package/lib/typescript/{views → src/views}/CourierPreferencesView.d.ts +0 -0
@@ -1,524 +0,0 @@
1
- import Courier_iOS
2
-
3
- @objc(CourierReactNativeModule)
4
- class CourierReactNativeModule: RCTEventEmitter {
5
-
6
- private static let COURIER_ERROR_TAG = "Courier iOS SDK Error"
7
-
8
- class LogEvents {
9
- internal static let DEBUG_LOG = "courierDebugEvent"
10
- }
11
-
12
- class PushEvents {
13
- internal static let CLICKED_EVENT = "pushNotificationClicked"
14
- internal static let DELIVERED_EVENT = "pushNotificationDelivered"
15
- }
16
-
17
- private var events = [String]()
18
-
19
- // Listeners
20
- private var authListeners: [String: CourierAuthenticationListener] = [:]
21
- private var inboxListeners: [String: CourierInboxListener] = [:]
22
-
23
- private var lastClickedMessage: [AnyHashable: Any]? = nil
24
- private var notificationCenter: NotificationCenter {
25
- get {
26
- return NotificationCenter.default
27
- }
28
- }
29
-
30
- override init() {
31
- super.init()
32
-
33
- // Set the user agent
34
- // Used to know the platform performing requests
35
- Courier.agent = CourierAgent.react_native_ios
36
-
37
- // Attach the listeners
38
- attachObservers()
39
-
40
- }
41
-
42
- override func startObserving() {
43
-
44
- // Setup debug listeners
45
- Courier.shared.logListener = { log in
46
- self.broadcastEvent(
47
- name: CourierReactNativeModule.LogEvents.DEBUG_LOG,
48
- body: log
49
- )
50
- }
51
-
52
- }
53
-
54
- override func stopObserving() {
55
- removeAuthListeners()
56
- removeInboxListeners()
57
- }
58
-
59
- private func removeAuthListeners() {
60
-
61
- authListeners.forEach { key, value in
62
- value.remove()
63
- }
64
-
65
- authListeners.removeAll()
66
-
67
- }
68
-
69
- private func removeInboxListeners() {
70
-
71
- inboxListeners.forEach { key, value in
72
- value.remove()
73
- }
74
-
75
- inboxListeners.removeAll()
76
-
77
- }
78
-
79
- private func attachObservers() {
80
-
81
- notificationCenter.addObserver(
82
- self,
83
- selector: #selector(pushNotificationClicked),
84
- name: Notification.Name(rawValue: CourierReactNativeModule.PushEvents.CLICKED_EVENT),
85
- object: nil
86
- )
87
-
88
- notificationCenter.addObserver(
89
- self,
90
- selector: #selector(pushNotificationDelivered),
91
- name: Notification.Name(rawValue: CourierReactNativeModule.PushEvents.DELIVERED_EVENT),
92
- object: nil
93
- )
94
-
95
- }
96
-
97
- @objc(setDebugMode:)
98
- func setDebugMode(isDebugging: Bool) -> String {
99
- Courier.shared.isDebugging = isDebugging
100
- return String(describing: Courier.shared.isDebugging)
101
- }
102
-
103
- private func sendMessage(name: String, message: [AnyHashable: Any]?) {
104
-
105
- guard let message = message else {
106
- return
107
- }
108
-
109
- do {
110
- broadcastEvent(
111
- name: name,
112
- body: try message.toString()
113
- )
114
- } catch {
115
- Courier.log(String(describing: error))
116
- }
117
-
118
- }
119
-
120
- private func broadcastEvent(name: String, body: Any?) {
121
-
122
- if (!supportedEvents().contains(name)) {
123
- return
124
- }
125
-
126
- sendEvent(
127
- withName: name,
128
- body: body
129
- )
130
-
131
- }
132
-
133
- @objc private func pushNotificationClicked(notification: Notification) {
134
-
135
- lastClickedMessage = notification.userInfo
136
- sendMessage(
137
- name: CourierReactNativeModule.PushEvents.CLICKED_EVENT,
138
- message: lastClickedMessage
139
- )
140
-
141
- }
142
-
143
- @objc private func pushNotificationDelivered(notification: Notification) {
144
-
145
- sendMessage(
146
- name: CourierReactNativeModule.PushEvents.DELIVERED_EVENT,
147
- message: notification.userInfo
148
- )
149
-
150
- }
151
-
152
- @objc func registerPushNotificationClickedOnKilledState() {
153
-
154
- sendMessage(
155
- name: CourierReactNativeModule.PushEvents.CLICKED_EVENT,
156
- message: lastClickedMessage
157
- )
158
-
159
- }
160
-
161
- @objc(getNotificationPermissionStatus: withRejecter:)
162
- func getNotificationPermissionStatus(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
163
-
164
- Courier.getNotificationPermissionStatus { status in
165
- resolve(status.name)
166
- }
167
-
168
- }
169
-
170
- @objc(requestNotificationPermission: withRejecter:)
171
- func requestNotificationPermission(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
172
-
173
- Courier.requestNotificationPermission { status in
174
- resolve(status.name)
175
- }
176
-
177
- }
178
-
179
- @objc(signIn: withClientKey: withUserId: withTenantId: withResolver: withRejecter:)
180
- func signIn(accessToken: NSString, clientKey: NSString?, userId: NSString, tenantId: NSString?, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
181
-
182
- Courier.shared.signIn(
183
- accessToken: accessToken as String,
184
- clientKey: clientKey as? String,
185
- userId: userId as String,
186
- tenantId: tenantId as? String
187
- ) {
188
- resolve(nil)
189
- }
190
-
191
- }
192
-
193
- @objc(signOut: withRejecter:)
194
- func signOut(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
195
-
196
- Courier.shared.signOut {
197
- resolve(nil)
198
- }
199
-
200
- }
201
-
202
- @objc func getUserId() -> String? {
203
- return Courier.shared.userId
204
- }
205
-
206
- @objc func getTenantId() -> String? {
207
- return Courier.shared.tenantId
208
- }
209
-
210
- @objc(addAuthenticationListener:)
211
- func addAuthenticationListener(authId: String) -> String {
212
-
213
- events.append(authId)
214
-
215
- let listener = Courier.shared.addAuthenticationListener { [weak self] userId in
216
- self?.broadcastEvent(
217
- name: authId,
218
- body: userId
219
- )
220
- }
221
-
222
- let id = UUID().uuidString
223
- authListeners[id] = listener
224
-
225
- return id
226
-
227
- }
228
-
229
- @objc(removeAuthenticationListener:)
230
- func removeAuthenticationListener(listenerId: NSString) -> String {
231
-
232
- let id = listenerId as String
233
-
234
- let listener = authListeners[id]
235
-
236
- // Disable the listener
237
- listener?.remove()
238
-
239
- // Remove the id from the map
240
- authListeners.removeValue(forKey: id)
241
-
242
- return id
243
-
244
- }
245
-
246
- @objc(setToken: withToken: withResolver: withRejecter:)
247
- func setToken(key: NSString, token: NSString, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
248
-
249
- Courier.shared.setToken(
250
- providerKey: key as String,
251
- token: token as String,
252
- onSuccess: {
253
- resolve(nil)
254
- },
255
- onFailure: { error in
256
- reject(String(describing: error), CourierReactNativeModule.COURIER_ERROR_TAG, nil)
257
- }
258
- )
259
-
260
- }
261
-
262
- @objc(getToken: withResolver: withRejecter:)
263
- func getToken(key: NSString, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
264
-
265
- let provider = key as String
266
-
267
- Task {
268
-
269
- let token = await Courier.shared.getToken(providerKey: provider)
270
- resolve(token)
271
-
272
- }
273
-
274
- }
275
-
276
- @objc(iOSForegroundPresentationOptions:)
277
- func iOSForegroundPresentationOptions(params: NSDictionary) -> String {
278
-
279
- let rawValue = params.toPresentationOptions().rawValue
280
- NotificationCenter.default.post(
281
- name: Notification.Name("iosForegroundNotificationPresentationOptions"),
282
- object: nil,
283
- userInfo: ["options": rawValue]
284
- )
285
-
286
- return String(describing: rawValue)
287
-
288
- }
289
-
290
- @objc(clickMessage:)
291
- func clickMessage(messageId: NSString) -> String {
292
- let id = messageId as String
293
- Courier.shared.clickMessage(messageId: id)
294
- return id
295
- }
296
-
297
- @objc(readMessage:)
298
- func readMessage(messageId: NSString) -> String {
299
- let id = messageId as String
300
- Courier.shared.readMessage(messageId: id)
301
- return id
302
- }
303
-
304
- @objc(unreadMessage:)
305
- func unreadMessage(messageId: NSString) -> String {
306
- let id = messageId as String
307
- Courier.shared.unreadMessage(messageId: id)
308
- return id
309
- }
310
-
311
- @objc(readAllInboxMessages: withRejecter:)
312
- func readAllInboxMessages(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
313
-
314
- Courier.shared.readAllInboxMessages(
315
- onSuccess: {
316
- resolve(nil)
317
- },
318
- onFailure: { error in
319
- reject(String(describing: error), CourierReactNativeModule.COURIER_ERROR_TAG, nil)
320
- }
321
- )
322
-
323
- }
324
-
325
- @objc(addInboxListener: withErrorId: withMessagesId:)
326
- func addInboxListener(loadingId: String, errorId: String, messagesId: String) -> String {
327
-
328
- // Add the events
329
- events.append(contentsOf: [loadingId, errorId, messagesId])
330
-
331
- // Create the new listener
332
- let listener = Courier.shared.addInboxListener(
333
- onInitialLoad: { [weak self] in
334
-
335
- self?.broadcastEvent(
336
- name: loadingId,
337
- body: nil
338
- )
339
-
340
- },
341
- onError: { [weak self] error in
342
-
343
- self?.broadcastEvent(
344
- name: errorId,
345
- body: String(describing: error)
346
- )
347
-
348
- },
349
- onMessagesChanged: { [weak self] messages, unreadMessageCount, totalMessageCount, canPaginate in
350
-
351
- let json: [String: Any] = [
352
- "messages": messages.map { $0.toDictionary() },
353
- "unreadMessageCount": unreadMessageCount,
354
- "totalMessageCount": totalMessageCount,
355
- "canPaginate": canPaginate
356
- ]
357
-
358
- self?.broadcastEvent(
359
- name: messagesId,
360
- body: json
361
- )
362
-
363
- }
364
- )
365
-
366
- let id = UUID().uuidString
367
- inboxListeners[id] = listener
368
-
369
- return id
370
-
371
- }
372
-
373
- @objc(removeInboxListener:)
374
- func removeInboxListener(listenerId: NSString) -> String {
375
-
376
- let id = listenerId as String
377
-
378
- let listener = inboxListeners[id]
379
-
380
- // Disable the listener
381
- listener?.remove()
382
-
383
- // Remove the id from the map
384
- inboxListeners.removeValue(forKey: id)
385
-
386
- return id
387
-
388
- }
389
-
390
- @objc(refreshInbox: withRejecter:)
391
- func refreshInbox(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
392
-
393
- Courier.shared.refreshInbox {
394
- resolve(nil)
395
- }
396
-
397
- }
398
-
399
- @objc(fetchNextPageOfMessages: withRejecter:)
400
- func fetchNextPageOfMessages(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
401
-
402
- Courier.shared.fetchNextPageOfMessages(
403
- onSuccess: { messages in
404
- resolve(messages.map { $0.toDictionary() })
405
- },
406
- onFailure: { error in
407
- reject(String(describing: error), CourierReactNativeModule.COURIER_ERROR_TAG, nil)
408
- }
409
- )
410
-
411
- }
412
-
413
- @objc(setInboxPaginationLimit:)
414
- func setInboxPaginationLimit(limit: Double) -> String {
415
- Courier.shared.inboxPaginationLimit = Int(limit)
416
- return String(describing: Courier.shared.inboxPaginationLimit)
417
- }
418
-
419
- @objc(getUserPreferences: withResolver: withRejecter:)
420
- func getUserPreferences(paginationCursor: NSString, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
421
-
422
- let cursor = paginationCursor != "" ? paginationCursor as String : nil
423
-
424
- Courier.shared.getUserPreferences(
425
- paginationCursor: cursor,
426
- onSuccess: { preferences in
427
- resolve(preferences.toDictionary())
428
- },
429
- onFailure: { error in
430
- reject(String(describing: error), CourierReactNativeModule.COURIER_ERROR_TAG, nil)
431
- }
432
- )
433
-
434
- }
435
-
436
- @objc(getUserPreferencesTopic: withResolver: withRejecter:)
437
- func getUserPreferencesTopic(topicId: NSString, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
438
-
439
- Courier.shared.getUserPreferencesTopic(
440
- topicId: topicId as String,
441
- onSuccess: { topic in
442
- resolve(topic.toDictionary())
443
- },
444
- onFailure: { error in
445
- reject(String(describing: error), CourierReactNativeModule.COURIER_ERROR_TAG, nil)
446
- }
447
- )
448
-
449
- }
450
-
451
- @objc(putUserPreferencesTopic: withStatus: withHasCustomRouting: withCustomRouting: withResolver: withRejecter:)
452
- func putUserPreferencesTopic(topicId: NSString, status: NSString, hasCustomRouting: Bool, customRouting: [NSString], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
453
-
454
- Courier.shared.putUserPreferencesTopic(
455
- topicId: topicId as String,
456
- status: CourierUserPreferencesStatus(rawValue: status as String) ?? .unknown,
457
- hasCustomRouting: hasCustomRouting,
458
- customRouting: customRouting.map { CourierUserPreferencesChannel(rawValue: $0 as String) ?? .unknown },
459
- onSuccess: {
460
- resolve(nil)
461
- },
462
- onFailure: { error in
463
- reject(String(describing: error), CourierReactNativeModule.COURIER_ERROR_TAG, nil)
464
- }
465
- )
466
-
467
- }
468
-
469
- override func supportedEvents() -> [String]! {
470
-
471
- // Built in events
472
- var allEvents = [
473
- CourierReactNativeModule.LogEvents.DEBUG_LOG,
474
- CourierReactNativeModule.PushEvents.CLICKED_EVENT,
475
- CourierReactNativeModule.PushEvents.DELIVERED_EVENT
476
- ]
477
-
478
- allEvents.append(contentsOf: events)
479
- // let authIds = authListeners.map { $0.value.authId }
480
- // events.append(contentsOf: authIds)
481
-
482
- return allEvents
483
-
484
- }
485
-
486
- @objc override static func requiresMainQueueSetup() -> Bool {
487
- return true
488
- }
489
-
490
- }
491
-
492
- extension [AnyHashable: Any] {
493
-
494
- func toString() throws -> String {
495
- let json = try JSONSerialization.data(withJSONObject: self)
496
- let str = String(data: json, encoding: .utf8)
497
- return str ?? "Invalid JSON"
498
- }
499
-
500
- }
501
-
502
- extension NSDictionary {
503
-
504
- func toPresentationOptions() -> UNNotificationPresentationOptions {
505
-
506
- var foregroundPresentationOptions: UNNotificationPresentationOptions = []
507
-
508
- if let options = self["options"] as? [String] {
509
- options.forEach { option in
510
- switch option {
511
- case "sound": foregroundPresentationOptions.insert(.sound)
512
- case "badge": foregroundPresentationOptions.insert(.badge)
513
- case "list": if #available(iOS 14.0, *) { foregroundPresentationOptions.insert(.list) } else { foregroundPresentationOptions.insert(.alert) }
514
- case "banner": if #available(iOS 14.0, *) { foregroundPresentationOptions.insert(.banner) } else { foregroundPresentationOptions.insert(.alert) }
515
- default: break
516
- }
517
- }
518
- }
519
-
520
- return foregroundPresentationOptions
521
-
522
- }
523
-
524
- }
@@ -1,17 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.CourierUserPreferencesChannel = void 0;
7
- let CourierUserPreferencesChannel = /*#__PURE__*/function (CourierUserPreferencesChannel) {
8
- CourierUserPreferencesChannel["DirectMessage"] = "direct_message";
9
- CourierUserPreferencesChannel["Email"] = "email";
10
- CourierUserPreferencesChannel["Push"] = "push";
11
- CourierUserPreferencesChannel["SMS"] = "sms";
12
- CourierUserPreferencesChannel["Webhook"] = "webhook";
13
- CourierUserPreferencesChannel["Unknown"] = "unknown";
14
- return CourierUserPreferencesChannel;
15
- }({});
16
- exports.CourierUserPreferencesChannel = CourierUserPreferencesChannel;
17
- //# sourceMappingURL=CourierUserPreferencesChannel.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["CourierUserPreferencesChannel","exports"],"sourceRoot":"../../../src","sources":["models/CourierUserPreferencesChannel.tsx"],"mappings":";;;;;;IAAYA,6BAA6B,0BAA7BA,6BAA6B;EAA7BA,6BAA6B;EAA7BA,6BAA6B;EAA7BA,6BAA6B;EAA7BA,6BAA6B;EAA7BA,6BAA6B;EAA7BA,6BAA6B;EAAA,OAA7BA,6BAA6B;AAAA;AAAAC,OAAA,CAAAD,6BAAA,GAAAA,6BAAA"}
@@ -1,15 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.CourierUserPreferencesStatus = void 0;
7
- let CourierUserPreferencesStatus = /*#__PURE__*/function (CourierUserPreferencesStatus) {
8
- CourierUserPreferencesStatus["OptedIn"] = "OPTED_IN";
9
- CourierUserPreferencesStatus["OptedOut"] = "OPTED_OUT";
10
- CourierUserPreferencesStatus["Required"] = "REQUIRED";
11
- CourierUserPreferencesStatus["Unknown"] = "UNKNOWN";
12
- return CourierUserPreferencesStatus;
13
- }({});
14
- exports.CourierUserPreferencesStatus = CourierUserPreferencesStatus;
15
- //# sourceMappingURL=CourierUserPreferencesStatus.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["CourierUserPreferencesStatus","exports"],"sourceRoot":"../../../src","sources":["models/CourierUserPreferencesStatus.tsx"],"mappings":";;;;;;IAAYA,4BAA4B,0BAA5BA,4BAA4B;EAA5BA,4BAA4B;EAA5BA,4BAA4B;EAA5BA,4BAA4B;EAA5BA,4BAA4B;EAAA,OAA5BA,4BAA4B;AAAA;AAAAC,OAAA,CAAAD,4BAAA,GAAAA,4BAAA"}
@@ -1,10 +0,0 @@
1
- export let CourierUserPreferencesChannel = /*#__PURE__*/function (CourierUserPreferencesChannel) {
2
- CourierUserPreferencesChannel["DirectMessage"] = "direct_message";
3
- CourierUserPreferencesChannel["Email"] = "email";
4
- CourierUserPreferencesChannel["Push"] = "push";
5
- CourierUserPreferencesChannel["SMS"] = "sms";
6
- CourierUserPreferencesChannel["Webhook"] = "webhook";
7
- CourierUserPreferencesChannel["Unknown"] = "unknown";
8
- return CourierUserPreferencesChannel;
9
- }({});
10
- //# sourceMappingURL=CourierUserPreferencesChannel.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["CourierUserPreferencesChannel"],"sourceRoot":"../../../src","sources":["models/CourierUserPreferencesChannel.tsx"],"mappings":"AAAA,WAAYA,6BAA6B,0BAA7BA,6BAA6B;EAA7BA,6BAA6B;EAA7BA,6BAA6B;EAA7BA,6BAA6B;EAA7BA,6BAA6B;EAA7BA,6BAA6B;EAA7BA,6BAA6B;EAAA,OAA7BA,6BAA6B;AAAA"}
@@ -1,8 +0,0 @@
1
- export let CourierUserPreferencesStatus = /*#__PURE__*/function (CourierUserPreferencesStatus) {
2
- CourierUserPreferencesStatus["OptedIn"] = "OPTED_IN";
3
- CourierUserPreferencesStatus["OptedOut"] = "OPTED_OUT";
4
- CourierUserPreferencesStatus["Required"] = "REQUIRED";
5
- CourierUserPreferencesStatus["Unknown"] = "UNKNOWN";
6
- return CourierUserPreferencesStatus;
7
- }({});
8
- //# sourceMappingURL=CourierUserPreferencesStatus.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["CourierUserPreferencesStatus"],"sourceRoot":"../../../src","sources":["models/CourierUserPreferencesStatus.tsx"],"mappings":"AAAA,WAAYA,4BAA4B,0BAA5BA,4BAA4B;EAA5BA,4BAA4B;EAA5BA,4BAA4B;EAA5BA,4BAA4B;EAA5BA,4BAA4B;EAAA,OAA5BA,4BAA4B;AAAA"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=CourierUserPreferencesTopic.js.map