@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.
- package/android/build.gradle +4 -1
- package/android/src/main/java/com/courierreactnative/CourierClientModule.kt +441 -0
- package/android/src/main/java/com/courierreactnative/CourierInboxViewManager.kt +2 -2
- package/android/src/main/java/com/courierreactnative/CourierReactNativePackage.kt +9 -3
- package/android/src/main/java/com/courierreactnative/CourierSharedModule.kt +321 -0
- package/android/src/main/java/com/courierreactnative/CourierSystemModule.kt +91 -0
- package/android/src/main/java/com/courierreactnative/ReactNativeModule.kt +36 -0
- package/android/src/main/java/com/courierreactnative/{Extensions.kt → Utils.kt} +5 -5
- package/courier-react-native.podspec +1 -1
- package/ios/CourierClientModule.swift +450 -0
- package/ios/CourierInboxReactNativeManager.swift +17 -9
- package/ios/CourierReactNativeDelegate.m +18 -35
- package/ios/CourierReactNativeEventEmitter.swift +25 -0
- package/ios/CourierReactNativeModule.m +192 -23
- package/ios/CourierSharedModule.swift +425 -0
- package/ios/CourierSystemModule.swift +147 -0
- package/ios/Utils.swift +103 -115
- package/lib/commonjs/Broadcaster.js +30 -0
- package/lib/commonjs/Broadcaster.js.map +1 -0
- package/lib/commonjs/Modules.js +25 -0
- package/lib/commonjs/Modules.js.map +1 -0
- package/lib/commonjs/client/BrandClient.js +25 -0
- package/lib/commonjs/client/BrandClient.js.map +1 -0
- package/lib/commonjs/client/ClientModule.js +21 -0
- package/lib/commonjs/client/ClientModule.js.map +1 -0
- package/lib/commonjs/client/CourierClient.js +33 -0
- package/lib/commonjs/client/CourierClient.js.map +1 -0
- package/lib/commonjs/client/InboxClient.js +116 -0
- package/lib/commonjs/client/InboxClient.js.map +1 -0
- package/lib/commonjs/client/PreferenceClient.js +73 -0
- package/lib/commonjs/client/PreferenceClient.js.map +1 -0
- package/lib/commonjs/client/TokenClient.js +36 -0
- package/lib/commonjs/client/TokenClient.js.map +1 -0
- package/lib/commonjs/client/TrackingClient.js +25 -0
- package/lib/commonjs/client/TrackingClient.js.map +1 -0
- package/lib/commonjs/index.js +418 -186
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/models/Android_CourierSheet.js.map +1 -1
- package/lib/commonjs/models/CourierAuthenticationListener.js.map +1 -1
- package/lib/commonjs/models/CourierBrand.js +2 -0
- package/lib/commonjs/models/{CourierUserPreferencesTopic.js.map → CourierBrand.js.map} +1 -1
- package/lib/commonjs/models/CourierButton.js.map +1 -1
- package/lib/commonjs/models/CourierDevice.js +2 -0
- package/lib/commonjs/models/CourierDevice.js.map +1 -0
- package/lib/commonjs/models/CourierFont.js.map +1 -1
- package/lib/commonjs/models/CourierInboxListener.js +2 -2
- package/lib/commonjs/models/CourierInboxListener.js.map +1 -1
- package/lib/commonjs/models/{CourierUserPreferencesTopic.js → CourierInboxMessages.js} +1 -1
- package/lib/commonjs/models/CourierInboxMessages.js.map +1 -0
- package/lib/commonjs/models/CourierInboxTheme.js.map +1 -1
- package/lib/commonjs/models/CourierInfoViewStyle.js.map +1 -1
- package/lib/commonjs/models/CourierPaging.js.map +1 -1
- package/lib/commonjs/models/CourierPreferencesTheme.js.map +1 -1
- package/lib/commonjs/models/CourierPushListener.js +7 -3
- package/lib/commonjs/models/CourierPushListener.js.map +1 -1
- package/lib/commonjs/models/CourierPushProvider.js.map +1 -1
- package/lib/commonjs/models/CourierTrackingEvent.js +16 -0
- package/lib/commonjs/models/CourierTrackingEvent.js.map +1 -0
- package/lib/commonjs/models/CourierUserPreferences.js +54 -0
- package/lib/commonjs/models/CourierUserPreferences.js.map +1 -1
- package/lib/commonjs/models/InboxAction.js.map +1 -1
- package/lib/commonjs/models/InboxMessage.js.map +1 -1
- package/lib/commonjs/models/iOS_CourierCell.js.map +1 -1
- package/lib/commonjs/models/iOS_CourierSheet.js.map +1 -1
- package/lib/commonjs/utils.js +9 -17
- package/lib/commonjs/utils.js.map +1 -1
- package/lib/commonjs/views/CourierInboxView.js +3 -3
- package/lib/commonjs/views/CourierInboxView.js.map +1 -1
- package/lib/commonjs/views/CourierPreferencesView.js.map +1 -1
- package/lib/module/Broadcaster.js +23 -0
- package/lib/module/Broadcaster.js.map +1 -0
- package/lib/module/Modules.js +18 -0
- package/lib/module/Modules.js.map +1 -0
- package/lib/module/client/BrandClient.js +18 -0
- package/lib/module/client/BrandClient.js.map +1 -0
- package/lib/module/client/ClientModule.js +14 -0
- package/lib/module/client/ClientModule.js.map +1 -0
- package/lib/module/client/CourierClient.js +26 -0
- package/lib/module/client/CourierClient.js.map +1 -0
- package/lib/module/client/InboxClient.js +109 -0
- package/lib/module/client/InboxClient.js.map +1 -0
- package/lib/module/client/PreferenceClient.js +66 -0
- package/lib/module/client/PreferenceClient.js.map +1 -0
- package/lib/module/client/TokenClient.js +29 -0
- package/lib/module/client/TokenClient.js.map +1 -0
- package/lib/module/client/TrackingClient.js +18 -0
- package/lib/module/client/TrackingClient.js.map +1 -0
- package/lib/module/index.js +383 -185
- package/lib/module/index.js.map +1 -1
- package/lib/module/models/Android_CourierSheet.js.map +1 -1
- package/lib/module/models/CourierAuthenticationListener.js.map +1 -1
- package/lib/module/models/CourierBrand.js +2 -0
- package/lib/module/models/{CourierUserPreferencesTopic.js.map → CourierBrand.js.map} +1 -1
- package/lib/module/models/CourierButton.js.map +1 -1
- package/lib/module/models/CourierDevice.js +2 -0
- package/lib/module/models/CourierDevice.js.map +1 -0
- package/lib/module/models/CourierFont.js.map +1 -1
- package/lib/module/models/CourierInboxListener.js +1 -1
- package/lib/module/models/CourierInboxListener.js.map +1 -1
- package/lib/module/models/CourierInboxMessages.js +2 -0
- package/lib/module/models/CourierInboxMessages.js.map +1 -0
- package/lib/module/models/CourierInboxTheme.js.map +1 -1
- package/lib/module/models/CourierInfoViewStyle.js.map +1 -1
- package/lib/module/models/CourierPaging.js.map +1 -1
- package/lib/module/models/CourierPreferencesTheme.js.map +1 -1
- package/lib/module/models/CourierPushListener.js +7 -3
- package/lib/module/models/CourierPushListener.js.map +1 -1
- package/lib/module/models/CourierPushProvider.js.map +1 -1
- package/lib/module/models/CourierTrackingEvent.js +9 -0
- package/lib/module/models/CourierTrackingEvent.js.map +1 -0
- package/lib/module/models/CourierUserPreferences.js +53 -1
- package/lib/module/models/CourierUserPreferences.js.map +1 -1
- package/lib/module/models/InboxAction.js.map +1 -1
- package/lib/module/models/InboxMessage.js.map +1 -1
- package/lib/module/models/iOS_CourierCell.js.map +1 -1
- package/lib/module/models/iOS_CourierSheet.js.map +1 -1
- package/lib/module/utils.js +7 -16
- package/lib/module/utils.js.map +1 -1
- package/lib/module/views/CourierInboxView.js +3 -3
- package/lib/module/views/CourierInboxView.js.map +1 -1
- package/lib/module/views/CourierPreferencesView.js.map +1 -1
- package/lib/typescript/src/Broadcaster.d.ts +14 -0
- package/lib/typescript/src/Broadcaster.d.ts.map +1 -0
- package/lib/typescript/src/Modules.d.ts +8 -0
- package/lib/typescript/src/Modules.d.ts.map +1 -0
- package/lib/typescript/src/client/BrandClient.d.ts +15 -0
- package/lib/typescript/src/client/BrandClient.d.ts.map +1 -0
- package/lib/typescript/src/client/ClientModule.d.ts +8 -0
- package/lib/typescript/src/client/ClientModule.d.ts.map +1 -0
- package/lib/typescript/src/client/CourierClient.d.ts +31 -0
- package/lib/typescript/src/client/CourierClient.d.ts.map +1 -0
- package/lib/typescript/src/client/InboxClient.d.ts +94 -0
- package/lib/typescript/src/client/InboxClient.d.ts.map +1 -0
- package/lib/typescript/src/client/PreferenceClient.d.ts +39 -0
- package/lib/typescript/src/client/PreferenceClient.d.ts.map +1 -0
- package/lib/typescript/src/client/TokenClient.d.ts +28 -0
- package/lib/typescript/src/client/TokenClient.d.ts.map +1 -0
- package/lib/typescript/src/client/TrackingClient.d.ts +17 -0
- package/lib/typescript/src/client/TrackingClient.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +300 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/models/Android_CourierSheet.d.ts.map +1 -0
- package/lib/typescript/src/models/CourierAuthenticationListener.d.ts.map +1 -0
- package/lib/typescript/src/models/CourierBrand.d.ts +20 -0
- package/lib/typescript/src/models/CourierBrand.d.ts.map +1 -0
- package/lib/typescript/src/models/CourierButton.d.ts.map +1 -0
- package/lib/typescript/src/models/CourierDevice.d.ts +9 -0
- package/lib/typescript/src/models/CourierDevice.d.ts.map +1 -0
- package/lib/typescript/src/models/CourierFont.d.ts.map +1 -0
- package/lib/typescript/src/models/CourierInboxListener.d.ts.map +1 -0
- package/lib/typescript/src/models/CourierInboxMessages.d.ts +23 -0
- package/lib/typescript/src/models/CourierInboxMessages.d.ts.map +1 -0
- package/lib/typescript/src/models/CourierInboxTheme.d.ts.map +1 -0
- package/lib/typescript/src/models/CourierInfoViewStyle.d.ts.map +1 -0
- package/lib/typescript/src/models/CourierPaging.d.ts.map +1 -0
- package/lib/typescript/src/models/CourierPreferencesTheme.d.ts.map +1 -0
- package/lib/typescript/src/models/CourierPushListener.d.ts +8 -0
- package/lib/typescript/src/models/CourierPushListener.d.ts.map +1 -0
- package/lib/typescript/src/models/CourierPushProvider.d.ts.map +1 -0
- package/lib/typescript/src/models/CourierTrackingEvent.d.ts +8 -0
- package/lib/typescript/src/models/CourierTrackingEvent.d.ts.map +1 -0
- package/lib/typescript/src/models/CourierUserPreferences.d.ts +35 -0
- package/lib/typescript/src/models/CourierUserPreferences.d.ts.map +1 -0
- package/lib/typescript/src/models/InboxAction.d.ts.map +1 -0
- package/lib/typescript/src/models/InboxMessage.d.ts.map +1 -0
- package/lib/typescript/src/models/iOS_CourierCell.d.ts.map +1 -0
- package/lib/typescript/src/models/iOS_CourierSheet.d.ts.map +1 -0
- package/lib/typescript/src/utils.d.ts +14 -0
- package/lib/typescript/src/utils.d.ts.map +1 -0
- package/lib/typescript/src/views/CourierInboxView.d.ts.map +1 -0
- package/lib/typescript/src/views/CourierPreferencesView.d.ts.map +1 -0
- package/package.json +3 -3
- package/src/Broadcaster.tsx +32 -0
- package/src/Modules.tsx +28 -0
- package/src/client/BrandClient.tsx +23 -0
- package/src/client/ClientModule.tsx +21 -0
- package/src/client/CourierClient.tsx +49 -0
- package/src/client/InboxClient.tsx +114 -0
- package/src/client/PreferenceClient.tsx +77 -0
- package/src/client/TokenClient.tsx +34 -0
- package/src/client/TrackingClient.tsx +23 -0
- package/src/index.tsx +398 -205
- package/src/models/CourierBrand.tsx +24 -0
- package/src/models/CourierDevice.tsx +8 -0
- package/src/models/CourierInboxListener.tsx +1 -1
- package/src/models/CourierInboxMessages.tsx +28 -0
- package/src/models/CourierPushListener.tsx +11 -6
- package/src/models/CourierTrackingEvent.tsx +7 -0
- package/src/models/CourierUserPreferences.tsx +70 -3
- package/src/utils.tsx +7 -23
- package/src/views/CourierInboxView.tsx +3 -3
- package/android/src/main/java/com/courierreactnative/CourierReactNativeModule.kt +0 -393
- package/ios/CourierReactNativeModule.swift +0 -524
- package/lib/commonjs/models/CourierUserPreferencesChannel.js +0 -17
- package/lib/commonjs/models/CourierUserPreferencesChannel.js.map +0 -1
- package/lib/commonjs/models/CourierUserPreferencesStatus.js +0 -15
- package/lib/commonjs/models/CourierUserPreferencesStatus.js.map +0 -1
- package/lib/module/models/CourierUserPreferencesChannel.js +0 -10
- package/lib/module/models/CourierUserPreferencesChannel.js.map +0 -1
- package/lib/module/models/CourierUserPreferencesStatus.js +0 -8
- package/lib/module/models/CourierUserPreferencesStatus.js.map +0 -1
- package/lib/module/models/CourierUserPreferencesTopic.js +0 -2
- package/lib/typescript/index.d.ts +0 -199
- package/lib/typescript/index.d.ts.map +0 -1
- package/lib/typescript/models/Android_CourierSheet.d.ts.map +0 -1
- package/lib/typescript/models/CourierAuthenticationListener.d.ts.map +0 -1
- package/lib/typescript/models/CourierButton.d.ts.map +0 -1
- package/lib/typescript/models/CourierFont.d.ts.map +0 -1
- package/lib/typescript/models/CourierInboxListener.d.ts.map +0 -1
- package/lib/typescript/models/CourierInboxTheme.d.ts.map +0 -1
- package/lib/typescript/models/CourierInfoViewStyle.d.ts.map +0 -1
- package/lib/typescript/models/CourierPaging.d.ts.map +0 -1
- package/lib/typescript/models/CourierPreferencesTheme.d.ts.map +0 -1
- package/lib/typescript/models/CourierPushListener.d.ts +0 -7
- package/lib/typescript/models/CourierPushListener.d.ts.map +0 -1
- package/lib/typescript/models/CourierPushProvider.d.ts.map +0 -1
- package/lib/typescript/models/CourierUserPreferences.d.ts +0 -7
- package/lib/typescript/models/CourierUserPreferences.d.ts.map +0 -1
- package/lib/typescript/models/CourierUserPreferencesChannel.d.ts +0 -9
- package/lib/typescript/models/CourierUserPreferencesChannel.d.ts.map +0 -1
- package/lib/typescript/models/CourierUserPreferencesStatus.d.ts +0 -7
- package/lib/typescript/models/CourierUserPreferencesStatus.d.ts.map +0 -1
- package/lib/typescript/models/CourierUserPreferencesTopic.d.ts +0 -13
- package/lib/typescript/models/CourierUserPreferencesTopic.d.ts.map +0 -1
- package/lib/typescript/models/InboxAction.d.ts.map +0 -1
- package/lib/typescript/models/InboxMessage.d.ts.map +0 -1
- package/lib/typescript/models/iOS_CourierCell.d.ts.map +0 -1
- package/lib/typescript/models/iOS_CourierSheet.d.ts.map +0 -1
- package/lib/typescript/utils.d.ts +0 -21
- package/lib/typescript/utils.d.ts.map +0 -1
- package/lib/typescript/views/CourierInboxView.d.ts.map +0 -1
- package/lib/typescript/views/CourierPreferencesView.d.ts.map +0 -1
- package/src/models/CourierUserPreferencesChannel.tsx +0 -8
- package/src/models/CourierUserPreferencesStatus.tsx +0 -6
- package/src/models/CourierUserPreferencesTopic.tsx +0 -13
- /package/lib/typescript/{models → src/models}/Android_CourierSheet.d.ts +0 -0
- /package/lib/typescript/{models → src/models}/CourierAuthenticationListener.d.ts +0 -0
- /package/lib/typescript/{models → src/models}/CourierButton.d.ts +0 -0
- /package/lib/typescript/{models → src/models}/CourierFont.d.ts +0 -0
- /package/lib/typescript/{models → src/models}/CourierInboxListener.d.ts +0 -0
- /package/lib/typescript/{models → src/models}/CourierInboxTheme.d.ts +0 -0
- /package/lib/typescript/{models → src/models}/CourierInfoViewStyle.d.ts +0 -0
- /package/lib/typescript/{models → src/models}/CourierPaging.d.ts +0 -0
- /package/lib/typescript/{models → src/models}/CourierPreferencesTheme.d.ts +0 -0
- /package/lib/typescript/{models → src/models}/CourierPushProvider.d.ts +0 -0
- /package/lib/typescript/{models → src/models}/InboxAction.d.ts +0 -0
- /package/lib/typescript/{models → src/models}/InboxMessage.d.ts +0 -0
- /package/lib/typescript/{models → src/models}/iOS_CourierCell.d.ts +0 -0
- /package/lib/typescript/{models → src/models}/iOS_CourierSheet.d.ts +0 -0
- /package/lib/typescript/{views → src/views}/CourierInboxView.d.ts +0 -0
- /package/lib/typescript/{views → src/views}/CourierPreferencesView.d.ts +0 -0
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
import Courier_iOS
|
|
2
|
+
|
|
3
|
+
@objc(CourierSharedModule)
|
|
4
|
+
class CourierSharedModule: RCTEventEmitter {
|
|
5
|
+
|
|
6
|
+
private var nativeEmitters = [String]()
|
|
7
|
+
private var authenticationListeners: [String: CourierAuthenticationListener] = [:]
|
|
8
|
+
private var inboxListeners: [String: CourierInboxListener] = [:]
|
|
9
|
+
|
|
10
|
+
override init() {
|
|
11
|
+
super.init()
|
|
12
|
+
|
|
13
|
+
// Set the user agent
|
|
14
|
+
// Used to know the platform performing requests
|
|
15
|
+
Courier.agent = CourierAgent.react_native_ios
|
|
16
|
+
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
override func stopObserving() {
|
|
20
|
+
removeAllAuthenticationListeners()
|
|
21
|
+
removeAllInboxListeners()
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// MARK: Client
|
|
25
|
+
|
|
26
|
+
@objc func getClient() -> String? {
|
|
27
|
+
|
|
28
|
+
guard let options = Courier.shared.client?.options else {
|
|
29
|
+
return nil
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
do {
|
|
33
|
+
|
|
34
|
+
let dictionary = [
|
|
35
|
+
"jwt": options.jwt as Any,
|
|
36
|
+
"clientKey": options.clientKey as Any,
|
|
37
|
+
"userId": options.userId as Any,
|
|
38
|
+
"connectionId": options.connectionId as Any,
|
|
39
|
+
"tenantId": options.tenantId as Any,
|
|
40
|
+
"showLogs": options.showLogs as Any
|
|
41
|
+
]
|
|
42
|
+
.compactMapValues { $0 }
|
|
43
|
+
|
|
44
|
+
let jsonData = try JSONSerialization.data(
|
|
45
|
+
withJSONObject: dictionary,
|
|
46
|
+
options: .prettyPrinted
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
guard let jsonString = String(data: jsonData, encoding: .utf8) else {
|
|
50
|
+
return nil
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return jsonString
|
|
54
|
+
|
|
55
|
+
} catch {
|
|
56
|
+
return nil
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// MARK: Authentication
|
|
62
|
+
|
|
63
|
+
@objc func getUserId() -> String? {
|
|
64
|
+
return Courier.shared.userId
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
@objc func getTenantId() -> String? {
|
|
68
|
+
return Courier.shared.tenantId
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
@objc func getIsUserSignedIn() -> String {
|
|
72
|
+
return String(Courier.shared.isUserSignedIn)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
@objc(signIn:withClientKey:withUserId:withTenantId:withShowLogs:withResolver:withRejecter:)
|
|
76
|
+
func signIn(accessToken: NSString, clientKey: NSString?, userId: NSString, tenantId: NSString?, showLogs: Bool, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
|
77
|
+
|
|
78
|
+
let userId = userId as String
|
|
79
|
+
let tenantId = tenantId as? String
|
|
80
|
+
let accessToken = accessToken as String
|
|
81
|
+
let clientKey = clientKey as? String
|
|
82
|
+
|
|
83
|
+
Task {
|
|
84
|
+
|
|
85
|
+
await Courier.shared.signIn(
|
|
86
|
+
userId: userId,
|
|
87
|
+
tenantId: tenantId,
|
|
88
|
+
accessToken: accessToken,
|
|
89
|
+
clientKey: clientKey,
|
|
90
|
+
showLogs: showLogs
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
resolve(nil)
|
|
94
|
+
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
@objc(signOut:withRejecter:)
|
|
100
|
+
func signOut(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
|
101
|
+
|
|
102
|
+
Task {
|
|
103
|
+
await Courier.shared.signOut()
|
|
104
|
+
resolve(nil)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
@objc(addAuthenticationListener:)
|
|
110
|
+
func addAuthenticationListener(listenerId: String) -> String {
|
|
111
|
+
|
|
112
|
+
nativeEmitters.append(listenerId)
|
|
113
|
+
|
|
114
|
+
let listener = Courier.shared.addAuthenticationListener { [weak self] userId in
|
|
115
|
+
self?.broadcast(
|
|
116
|
+
name: listenerId,
|
|
117
|
+
body: userId
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
authenticationListeners[listenerId] = listener
|
|
122
|
+
|
|
123
|
+
return listenerId
|
|
124
|
+
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
@objc(removeAuthenticationListener:)
|
|
128
|
+
func removeAuthenticationListener(listenerId: NSString) -> String {
|
|
129
|
+
|
|
130
|
+
let id = listenerId as String
|
|
131
|
+
|
|
132
|
+
let listener = authenticationListeners[id]
|
|
133
|
+
|
|
134
|
+
// Disable the listener
|
|
135
|
+
listener?.remove()
|
|
136
|
+
|
|
137
|
+
// Remove the id from the map
|
|
138
|
+
authenticationListeners.removeValue(forKey: id)
|
|
139
|
+
|
|
140
|
+
return id
|
|
141
|
+
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
@discardableResult @objc func removeAllAuthenticationListeners() -> String? {
|
|
145
|
+
|
|
146
|
+
for value in authenticationListeners.values {
|
|
147
|
+
value.remove()
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
authenticationListeners.removeAll()
|
|
151
|
+
|
|
152
|
+
return nil
|
|
153
|
+
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// MARK: Push
|
|
157
|
+
|
|
158
|
+
@objc(getAllTokens:withRejecter:)
|
|
159
|
+
func getAllTokens(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
160
|
+
|
|
161
|
+
Task {
|
|
162
|
+
|
|
163
|
+
let tokens = await Courier.shared.tokens
|
|
164
|
+
resolve(tokens)
|
|
165
|
+
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
@objc(getToken:withResolver:withRejecter:)
|
|
171
|
+
func getToken(provider: NSString, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
172
|
+
|
|
173
|
+
let provider = provider as String
|
|
174
|
+
|
|
175
|
+
Task {
|
|
176
|
+
|
|
177
|
+
let token = await Courier.shared.getToken(for: provider)
|
|
178
|
+
resolve(token)
|
|
179
|
+
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
@objc(setToken:withToken:withResolver:withRejecter:)
|
|
185
|
+
func setToken(provider: NSString, token: NSString, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
186
|
+
|
|
187
|
+
let provider = provider as String
|
|
188
|
+
let token = token as String
|
|
189
|
+
|
|
190
|
+
Task {
|
|
191
|
+
do {
|
|
192
|
+
try await Courier.shared.setToken(
|
|
193
|
+
for: provider,
|
|
194
|
+
token: token
|
|
195
|
+
)
|
|
196
|
+
resolve(nil)
|
|
197
|
+
} catch {
|
|
198
|
+
Rejections.sharedError(reject, error: error)
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// MARK: Inbox
|
|
205
|
+
|
|
206
|
+
@objc func getInboxPaginationLimit() -> String {
|
|
207
|
+
return String(describing: Courier.shared.inboxPaginationLimit)
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
@objc(setInboxPaginationLimit:)
|
|
211
|
+
func setInboxPaginationLimit(limit: Double) -> String {
|
|
212
|
+
Courier.shared.inboxPaginationLimit = Int(limit)
|
|
213
|
+
return String(describing: Courier.shared.inboxPaginationLimit)
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
@objc(openMessage:withResolver:withRejecter:)
|
|
217
|
+
func openMessage(messageId: NSString, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
218
|
+
|
|
219
|
+
let id = messageId as String
|
|
220
|
+
|
|
221
|
+
Task {
|
|
222
|
+
do {
|
|
223
|
+
try await Courier.shared.openMessage(id)
|
|
224
|
+
resolve(nil)
|
|
225
|
+
} catch {
|
|
226
|
+
Rejections.sharedError(reject, error: error)
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
@objc(archiveMessage:withResolver:withRejecter:)
|
|
233
|
+
func archiveMessage(messageId: NSString, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
234
|
+
|
|
235
|
+
let id = messageId as String
|
|
236
|
+
|
|
237
|
+
Task {
|
|
238
|
+
do {
|
|
239
|
+
try await Courier.shared.archiveMessage(id)
|
|
240
|
+
resolve(nil)
|
|
241
|
+
} catch {
|
|
242
|
+
Rejections.sharedError(reject, error: error)
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
@objc(clickMessage:withResolver:withRejecter:)
|
|
249
|
+
func clickMessage(messageId: NSString, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
250
|
+
|
|
251
|
+
let id = messageId as String
|
|
252
|
+
|
|
253
|
+
Task {
|
|
254
|
+
do {
|
|
255
|
+
try await Courier.shared.clickMessage(id)
|
|
256
|
+
resolve(nil)
|
|
257
|
+
} catch {
|
|
258
|
+
Rejections.sharedError(reject, error: error)
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
@objc(readMessage:withResolver:withRejecter:)
|
|
265
|
+
func readMessage(messageId: NSString, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
266
|
+
|
|
267
|
+
let id = messageId as String
|
|
268
|
+
|
|
269
|
+
Task {
|
|
270
|
+
do {
|
|
271
|
+
try await Courier.shared.readMessage(id)
|
|
272
|
+
resolve(nil)
|
|
273
|
+
} catch {
|
|
274
|
+
Rejections.sharedError(reject, error: error)
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
@objc(unreadMessage:withResolver:withRejecter:)
|
|
281
|
+
func unreadMessage(messageId: NSString, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
282
|
+
|
|
283
|
+
let id = messageId as String
|
|
284
|
+
|
|
285
|
+
Task {
|
|
286
|
+
do {
|
|
287
|
+
try await Courier.shared.unreadMessage(id)
|
|
288
|
+
resolve(nil)
|
|
289
|
+
} catch {
|
|
290
|
+
Rejections.sharedError(reject, error: error)
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
@objc(readAllInboxMessages:withRejecter:)
|
|
297
|
+
func readAllInboxMessages(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
298
|
+
|
|
299
|
+
Task {
|
|
300
|
+
do {
|
|
301
|
+
try await Courier.shared.readAllInboxMessages()
|
|
302
|
+
resolve(nil)
|
|
303
|
+
} catch {
|
|
304
|
+
Rejections.sharedError(reject, error: error)
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
@objc(addInboxListener: withErrorId: withMessagesId:)
|
|
311
|
+
func addInboxListener(loadingId: String, errorId: String, messagesId: String) -> String {
|
|
312
|
+
|
|
313
|
+
// Add the events
|
|
314
|
+
nativeEmitters.append(contentsOf: [loadingId, errorId, messagesId])
|
|
315
|
+
|
|
316
|
+
// Create the new listener
|
|
317
|
+
let listener = Courier.shared.addInboxListener(
|
|
318
|
+
onInitialLoad: { [weak self] in
|
|
319
|
+
self?.broadcast(
|
|
320
|
+
name: loadingId,
|
|
321
|
+
body: nil
|
|
322
|
+
)
|
|
323
|
+
},
|
|
324
|
+
onError: { [weak self] error in
|
|
325
|
+
self?.broadcast(
|
|
326
|
+
name: errorId,
|
|
327
|
+
body: String(describing: error)
|
|
328
|
+
)
|
|
329
|
+
},
|
|
330
|
+
onMessagesChanged: { [weak self] messages, unreadMessageCount, totalMessageCount, canPaginate in
|
|
331
|
+
|
|
332
|
+
do {
|
|
333
|
+
|
|
334
|
+
let json: [String: Any] = [
|
|
335
|
+
"messages": try messages.map { try $0.toJson() ?? "" },
|
|
336
|
+
"unreadMessageCount": unreadMessageCount,
|
|
337
|
+
"totalMessageCount": totalMessageCount,
|
|
338
|
+
"canPaginate": canPaginate
|
|
339
|
+
]
|
|
340
|
+
|
|
341
|
+
self?.broadcast(
|
|
342
|
+
name: messagesId,
|
|
343
|
+
body: json
|
|
344
|
+
)
|
|
345
|
+
|
|
346
|
+
} catch {
|
|
347
|
+
|
|
348
|
+
Courier.shared.client?.error(error.localizedDescription)
|
|
349
|
+
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
}
|
|
353
|
+
)
|
|
354
|
+
|
|
355
|
+
let id = UUID().uuidString
|
|
356
|
+
inboxListeners[id] = listener
|
|
357
|
+
|
|
358
|
+
return id
|
|
359
|
+
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
@objc(removeInboxListener:)
|
|
363
|
+
func removeInboxListener(listenerId: NSString) -> String {
|
|
364
|
+
|
|
365
|
+
let id = listenerId as String
|
|
366
|
+
|
|
367
|
+
let listener = inboxListeners[id]
|
|
368
|
+
|
|
369
|
+
// Disable the listener
|
|
370
|
+
listener?.remove()
|
|
371
|
+
|
|
372
|
+
// Remove the id from the map
|
|
373
|
+
inboxListeners.removeValue(forKey: id)
|
|
374
|
+
|
|
375
|
+
return id
|
|
376
|
+
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
@discardableResult @objc func removeAllInboxListeners() -> String? {
|
|
380
|
+
|
|
381
|
+
for value in inboxListeners.values {
|
|
382
|
+
value.remove()
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
inboxListeners.removeAll()
|
|
386
|
+
|
|
387
|
+
return nil
|
|
388
|
+
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
@objc(refreshInbox: withRejecter:)
|
|
392
|
+
func refreshInbox(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
|
393
|
+
|
|
394
|
+
Task {
|
|
395
|
+
await Courier.shared.refreshInbox()
|
|
396
|
+
resolve(nil)
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
@objc(fetchNextPageOfMessages: withRejecter:)
|
|
402
|
+
func fetchNextPageOfMessages(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
|
403
|
+
|
|
404
|
+
Task {
|
|
405
|
+
|
|
406
|
+
do {
|
|
407
|
+
let messages = try await Courier.shared.fetchNextInboxPage()
|
|
408
|
+
resolve(try messages.map { try $0.toJson() ?? "" })
|
|
409
|
+
} catch {
|
|
410
|
+
Rejections.sharedError(reject, error: error)
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
override func supportedEvents() -> [String]! {
|
|
418
|
+
return nativeEmitters
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
@objc override static func requiresMainQueueSetup() -> Bool {
|
|
422
|
+
return true
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
//
|
|
2
|
+
// CourierSystemModule.swift
|
|
3
|
+
// courier-react-native
|
|
4
|
+
//
|
|
5
|
+
// Created by Michael Miller on 8/27/24.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Courier_iOS
|
|
9
|
+
|
|
10
|
+
@objc(CourierSystemModule)
|
|
11
|
+
class CourierSystemModule: RCTEventEmitter {
|
|
12
|
+
|
|
13
|
+
private var lastClickedMessage: [AnyHashable: Any]? = nil
|
|
14
|
+
private var notificationCenter: NotificationCenter {
|
|
15
|
+
get { return NotificationCenter.default }
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
override init() {
|
|
19
|
+
super.init()
|
|
20
|
+
|
|
21
|
+
// Set the user agent
|
|
22
|
+
// Used to know the platform performing requests
|
|
23
|
+
Courier.agent = CourierAgent.react_native_ios
|
|
24
|
+
|
|
25
|
+
// Attach the listeners
|
|
26
|
+
attachObservers()
|
|
27
|
+
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// MARK: Push Interactions
|
|
31
|
+
|
|
32
|
+
private func attachObservers() {
|
|
33
|
+
|
|
34
|
+
notificationCenter.addObserver(
|
|
35
|
+
self,
|
|
36
|
+
selector: #selector(pushNotificationClicked),
|
|
37
|
+
name: Notification.Name(rawValue: PushEvents.CLICKED_EVENT),
|
|
38
|
+
object: nil
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
notificationCenter.addObserver(
|
|
42
|
+
self,
|
|
43
|
+
selector: #selector(pushNotificationDelivered),
|
|
44
|
+
name: Notification.Name(rawValue: PushEvents.DELIVERED_EVENT),
|
|
45
|
+
object: nil
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@objc private func pushNotificationClicked(notification: Notification) {
|
|
51
|
+
|
|
52
|
+
// Cache the last clicked message
|
|
53
|
+
lastClickedMessage = notification.userInfo
|
|
54
|
+
|
|
55
|
+
guard let message = lastClickedMessage else {
|
|
56
|
+
return
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
self.broadcast(
|
|
60
|
+
name: PushEvents.CLICKED_EVENT,
|
|
61
|
+
message: message
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
@objc private func pushNotificationDelivered(notification: Notification) {
|
|
67
|
+
|
|
68
|
+
guard let message = notification.userInfo else {
|
|
69
|
+
return
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
self.broadcast(
|
|
73
|
+
name: PushEvents.DELIVERED_EVENT,
|
|
74
|
+
message: message
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
@objc func registerPushNotificationClickedOnKilledState() {
|
|
80
|
+
|
|
81
|
+
guard let message = lastClickedMessage else {
|
|
82
|
+
return
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
broadcast(
|
|
86
|
+
name: PushEvents.CLICKED_EVENT,
|
|
87
|
+
message: message
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// MARK: Open App
|
|
93
|
+
|
|
94
|
+
@objc func openSettingsForApp() {
|
|
95
|
+
DispatchQueue.main.async {
|
|
96
|
+
Courier.openSettingsForApp()
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// MARK: Notification Permissions
|
|
101
|
+
|
|
102
|
+
@objc(getNotificationPermissionStatus:withRejecter:)
|
|
103
|
+
func getNotificationPermissionStatus(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
|
104
|
+
|
|
105
|
+
Courier.getNotificationPermissionStatus { status in
|
|
106
|
+
resolve(status.name)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
@objc(requestNotificationPermission:withRejecter:)
|
|
112
|
+
func requestNotificationPermission(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
|
|
113
|
+
|
|
114
|
+
Courier.requestNotificationPermission { status in
|
|
115
|
+
resolve(status.name)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// MARK: Notification Styling
|
|
121
|
+
|
|
122
|
+
@objc(setIOSForegroundPresentationOptions:)
|
|
123
|
+
func setIOSForegroundPresentationOptions(params: NSDictionary) -> String {
|
|
124
|
+
|
|
125
|
+
let rawValue = params.toPresentationOptions().rawValue
|
|
126
|
+
NotificationCenter.default.post(
|
|
127
|
+
name: Notification.Name("iosForegroundNotificationPresentationOptions"),
|
|
128
|
+
object: nil,
|
|
129
|
+
userInfo: ["options": rawValue]
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
return String(describing: rawValue)
|
|
133
|
+
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
override func supportedEvents() -> [String]! {
|
|
137
|
+
return [
|
|
138
|
+
PushEvents.CLICKED_EVENT,
|
|
139
|
+
PushEvents.DELIVERED_EVENT
|
|
140
|
+
]
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
@objc override static func requiresMainQueueSetup() -> Bool {
|
|
144
|
+
return true
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
}
|