@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,450 @@
|
|
|
1
|
+
//
|
|
2
|
+
// CourierClientModule.swift
|
|
3
|
+
// courier-react-native
|
|
4
|
+
//
|
|
5
|
+
// Created by Michael Miller on 8/21/24.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Courier_iOS
|
|
9
|
+
|
|
10
|
+
@objc(CourierClientModule)
|
|
11
|
+
internal class CourierClientModule: CourierReactNativeEventEmitter {
|
|
12
|
+
|
|
13
|
+
private var clients: [String: CourierClient] = [:]
|
|
14
|
+
|
|
15
|
+
@objc(addClient:)
|
|
16
|
+
func addClient(options: NSDictionary) -> String {
|
|
17
|
+
|
|
18
|
+
guard let userId = options["userId"] as? String, let showLogs = options["showLogs"] as? Bool else {
|
|
19
|
+
return "invalid"
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let client = CourierClient(
|
|
23
|
+
jwt: options["jwt"] as? String,
|
|
24
|
+
clientKey: options["clientKey"] as? String,
|
|
25
|
+
userId: userId,
|
|
26
|
+
connectionId: options["connectionId"] as? String,
|
|
27
|
+
tenantId: options["tenantId"] as? String,
|
|
28
|
+
showLogs: showLogs
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
let uuid = UUID().uuidString
|
|
32
|
+
clients[uuid] = client
|
|
33
|
+
|
|
34
|
+
return uuid
|
|
35
|
+
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@objc(removeClient:)
|
|
39
|
+
func removeClient(clientId: NSString) -> String {
|
|
40
|
+
let id = clientId as String
|
|
41
|
+
clients.removeValue(forKey: id)
|
|
42
|
+
return id
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// MARK: Tokens
|
|
46
|
+
|
|
47
|
+
@objc(putUserToken:withToken:withProvider:withDevice:withResolver:withRejecter:)
|
|
48
|
+
func putUserToken(clientId: NSString, token: NSString, provider: NSString, device: NSDictionary?, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
49
|
+
|
|
50
|
+
guard let client = clients[clientId as String] else {
|
|
51
|
+
Rejections.missingClient(reject)
|
|
52
|
+
return
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
let courierDevice: CourierDevice? = device.flatMap {
|
|
56
|
+
CourierDevice(
|
|
57
|
+
appId: $0["appId"] as? String,
|
|
58
|
+
adId: $0["adId"] as? String,
|
|
59
|
+
deviceId: $0["deviceId"] as? String,
|
|
60
|
+
platform: $0["platform"] as? String,
|
|
61
|
+
manufacturer: $0["manufacturer"] as? String,
|
|
62
|
+
model: $0["model"] as? String
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
let token = token as String
|
|
67
|
+
let provider = provider as String
|
|
68
|
+
|
|
69
|
+
Task {
|
|
70
|
+
do {
|
|
71
|
+
try await client.tokens.putUserToken(
|
|
72
|
+
token: token,
|
|
73
|
+
provider: provider,
|
|
74
|
+
device: courierDevice ?? CourierDevice()
|
|
75
|
+
)
|
|
76
|
+
resolve(nil)
|
|
77
|
+
} catch {
|
|
78
|
+
Rejections.clientError(reject, error: error)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@objc(deleteUserToken:withToken:withResolver:withRejecter:)
|
|
85
|
+
func deleteUserToken(clientId: NSString, token: NSString, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
86
|
+
|
|
87
|
+
guard let client = clients[clientId as String] else {
|
|
88
|
+
Rejections.missingClient(reject)
|
|
89
|
+
return
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
let token = token as String
|
|
93
|
+
|
|
94
|
+
Task {
|
|
95
|
+
do {
|
|
96
|
+
try await client.tokens.deleteUserToken(
|
|
97
|
+
token: token
|
|
98
|
+
)
|
|
99
|
+
resolve(nil)
|
|
100
|
+
} catch {
|
|
101
|
+
Rejections.clientError(reject, error: error)
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// MARK: Barnd
|
|
107
|
+
|
|
108
|
+
@objc(getBrand:withBrandId:withResolver:withRejecter:)
|
|
109
|
+
func getBrand(clientId: NSString, brandId: NSString, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
110
|
+
|
|
111
|
+
guard let client = clients[clientId as String] else {
|
|
112
|
+
Rejections.missingClient(reject)
|
|
113
|
+
return
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
let brandId = brandId as String
|
|
117
|
+
|
|
118
|
+
Task {
|
|
119
|
+
do {
|
|
120
|
+
let brand = try await client.brands.getBrand(
|
|
121
|
+
brandId: brandId
|
|
122
|
+
)
|
|
123
|
+
let json = try brand.toJson()
|
|
124
|
+
resolve(json)
|
|
125
|
+
} catch {
|
|
126
|
+
Rejections.clientError(reject, error: error)
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// MARK: Inbox
|
|
133
|
+
|
|
134
|
+
@objc(getMessages:withPaginationLimit:withStartCursor:withResolver:withRejecter:)
|
|
135
|
+
func getMessages(clientId: NSString, paginationLimit: Double, startCursor: NSString?, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
136
|
+
|
|
137
|
+
guard let client = clients[clientId as String] else {
|
|
138
|
+
Rejections.missingClient(reject)
|
|
139
|
+
return
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
let limit = Int(paginationLimit)
|
|
143
|
+
let startCursor = startCursor as? String
|
|
144
|
+
|
|
145
|
+
Task {
|
|
146
|
+
do {
|
|
147
|
+
let res = try await client.inbox.getMessages(
|
|
148
|
+
paginationLimit: limit,
|
|
149
|
+
startCursor: startCursor
|
|
150
|
+
)
|
|
151
|
+
let json = try res.toJson()
|
|
152
|
+
resolve(json)
|
|
153
|
+
} catch {
|
|
154
|
+
Rejections.clientError(reject, error: error)
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
@objc(getArchivedMessages:withPaginationLimit:withStartCursor:withResolver:withRejecter:)
|
|
160
|
+
func getArchivedMessages(clientId: NSString, paginationLimit: Double, startCursor: NSString?, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
161
|
+
|
|
162
|
+
guard let client = clients[clientId as String] else {
|
|
163
|
+
Rejections.missingClient(reject)
|
|
164
|
+
return
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
let limit = Int(paginationLimit)
|
|
168
|
+
let startCursor = startCursor as? String
|
|
169
|
+
|
|
170
|
+
Task {
|
|
171
|
+
do {
|
|
172
|
+
let res = try await client.inbox.getArchivedMessages(
|
|
173
|
+
paginationLimit: limit,
|
|
174
|
+
startCursor: startCursor
|
|
175
|
+
)
|
|
176
|
+
let json = try res.toJson()
|
|
177
|
+
resolve(json)
|
|
178
|
+
} catch {
|
|
179
|
+
Rejections.clientError(reject, error: error)
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
@objc(getMessageById:withMessageId:withResolver:withRejecter:)
|
|
185
|
+
func getMessageById(clientId: NSString, messageId: NSString, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
186
|
+
|
|
187
|
+
guard let client = clients[clientId as String] else {
|
|
188
|
+
Rejections.missingClient(reject)
|
|
189
|
+
return
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
let messageId = messageId as String
|
|
193
|
+
|
|
194
|
+
Task {
|
|
195
|
+
do {
|
|
196
|
+
let res = try await client.inbox.getMessage(messageId: messageId)
|
|
197
|
+
let json = try res.toJson()
|
|
198
|
+
resolve(json)
|
|
199
|
+
} catch {
|
|
200
|
+
Rejections.clientError(reject, error: error)
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
@objc(getUnreadMessageCount:withResolver:withRejecter:)
|
|
206
|
+
func getUnreadMessageCount(clientId: NSString, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
207
|
+
|
|
208
|
+
guard let client = clients[clientId as String] else {
|
|
209
|
+
Rejections.missingClient(reject)
|
|
210
|
+
return
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
Task {
|
|
214
|
+
do {
|
|
215
|
+
let count = try await client.inbox.getUnreadMessageCount()
|
|
216
|
+
resolve(count)
|
|
217
|
+
} catch {
|
|
218
|
+
Rejections.clientError(reject, error: error)
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
@objc(openMessage:withMessageId:withResolver:withRejecter:)
|
|
224
|
+
func openMessage(clientId: NSString, messageId: NSString, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
225
|
+
|
|
226
|
+
guard let client = clients[clientId as String] else {
|
|
227
|
+
Rejections.missingClient(reject)
|
|
228
|
+
return
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
let messageId = messageId as String
|
|
232
|
+
|
|
233
|
+
Task {
|
|
234
|
+
do {
|
|
235
|
+
try await client.inbox.open(
|
|
236
|
+
messageId: messageId
|
|
237
|
+
)
|
|
238
|
+
resolve(nil)
|
|
239
|
+
} catch {
|
|
240
|
+
Rejections.clientError(reject, error: error)
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
@objc(readMessage:withMessageId:withResolver:withRejecter:)
|
|
246
|
+
func readMessage(clientId: NSString, messageId: NSString, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
247
|
+
|
|
248
|
+
guard let client = clients[clientId as String] else {
|
|
249
|
+
Rejections.missingClient(reject)
|
|
250
|
+
return
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
let messageId = messageId as String
|
|
254
|
+
|
|
255
|
+
Task {
|
|
256
|
+
do {
|
|
257
|
+
try await client.inbox.read(
|
|
258
|
+
messageId: messageId
|
|
259
|
+
)
|
|
260
|
+
resolve(nil)
|
|
261
|
+
} catch {
|
|
262
|
+
Rejections.clientError(reject, error: error)
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
@objc(unreadMessage:withMessageId:withResolver:withRejecter:)
|
|
268
|
+
func unreadMessage(clientId: NSString, messageId: NSString, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
269
|
+
|
|
270
|
+
guard let client = clients[clientId as String] else {
|
|
271
|
+
Rejections.missingClient(reject)
|
|
272
|
+
return
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
let messageId = messageId as String
|
|
276
|
+
|
|
277
|
+
Task {
|
|
278
|
+
do {
|
|
279
|
+
try await client.inbox.unread(
|
|
280
|
+
messageId: messageId
|
|
281
|
+
)
|
|
282
|
+
resolve(nil)
|
|
283
|
+
} catch {
|
|
284
|
+
Rejections.clientError(reject, error: error)
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
@objc(clickMessage:withMessageId:withTrackingId:withResolver:withRejecter:)
|
|
290
|
+
func clickMessage(clientId: NSString, messageId: NSString, trackingId: NSString, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
291
|
+
|
|
292
|
+
guard let client = clients[clientId as String] else {
|
|
293
|
+
Rejections.missingClient(reject)
|
|
294
|
+
return
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
let messageId = messageId as String
|
|
298
|
+
let trackingId = trackingId as String
|
|
299
|
+
|
|
300
|
+
Task {
|
|
301
|
+
do {
|
|
302
|
+
try await client.inbox.click(
|
|
303
|
+
messageId: messageId,
|
|
304
|
+
trackingId: trackingId
|
|
305
|
+
)
|
|
306
|
+
resolve(nil)
|
|
307
|
+
} catch {
|
|
308
|
+
Rejections.clientError(reject, error: error)
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
@objc(archiveMessage:withMessageId:withResolver:withRejecter:)
|
|
314
|
+
func archiveMessage(clientId: NSString, messageId: NSString, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
315
|
+
|
|
316
|
+
guard let client = clients[clientId as String] else {
|
|
317
|
+
Rejections.missingClient(reject)
|
|
318
|
+
return
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
let messageId = messageId as String
|
|
322
|
+
|
|
323
|
+
Task {
|
|
324
|
+
do {
|
|
325
|
+
try await client.inbox.archive(
|
|
326
|
+
messageId: messageId
|
|
327
|
+
)
|
|
328
|
+
resolve(nil)
|
|
329
|
+
} catch {
|
|
330
|
+
Rejections.clientError(reject, error: error)
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
@objc(readAllMessages:withResolver:withRejecter:)
|
|
336
|
+
func readAllMessages(clientId: NSString, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
337
|
+
|
|
338
|
+
guard let client = clients[clientId as String] else {
|
|
339
|
+
Rejections.missingClient(reject)
|
|
340
|
+
return
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
Task {
|
|
344
|
+
do {
|
|
345
|
+
try await client.inbox.readAll()
|
|
346
|
+
resolve(nil)
|
|
347
|
+
} catch {
|
|
348
|
+
Rejections.clientError(reject, error: error)
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
@objc(getUserPreferences:withPaginationCursor:withResolver:withRejecter:)
|
|
354
|
+
func getUserPreferences(clientId: NSString, paginationCursor: NSString?, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
355
|
+
|
|
356
|
+
guard let client = clients[clientId as String] else {
|
|
357
|
+
Rejections.missingClient(reject)
|
|
358
|
+
return
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
let paginationCursor = paginationCursor as? String
|
|
362
|
+
|
|
363
|
+
Task {
|
|
364
|
+
do {
|
|
365
|
+
let res = try await client.preferences.getUserPreferences(
|
|
366
|
+
paginationCursor: paginationCursor
|
|
367
|
+
)
|
|
368
|
+
let json = try res.toJson()
|
|
369
|
+
resolve(json)
|
|
370
|
+
} catch {
|
|
371
|
+
Rejections.clientError(reject, error: error)
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
@objc(getUserPreferenceTopic:withTopicId:withResolver:withRejecter:)
|
|
377
|
+
func getUserPreferenceTopic(clientId: NSString, topicId: NSString, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
378
|
+
|
|
379
|
+
guard let client = clients[clientId as String] else {
|
|
380
|
+
Rejections.missingClient(reject)
|
|
381
|
+
return
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
let topicId = topicId as String
|
|
385
|
+
|
|
386
|
+
Task {
|
|
387
|
+
do {
|
|
388
|
+
let res = try await client.preferences.getUserPreferenceTopic(
|
|
389
|
+
topicId: topicId
|
|
390
|
+
)
|
|
391
|
+
let json = try res.toJson()
|
|
392
|
+
resolve(json)
|
|
393
|
+
} catch {
|
|
394
|
+
Rejections.clientError(reject, error: error)
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
@objc(putUserPreferenceTopic:withTopicId:withStatus:withHasCustomRouting:withCustomRouting:withResolver:withRejecter:)
|
|
400
|
+
func putUserPreferenceTopic(clientId: NSString, topicId: NSString, status: NSString, hasCustomRouting: Bool, customRouting: NSArray, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
401
|
+
|
|
402
|
+
guard let client = clients[clientId as String] else {
|
|
403
|
+
Rejections.missingClient(reject)
|
|
404
|
+
return
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
let topicId = topicId as String
|
|
408
|
+
let status = status as String
|
|
409
|
+
let customRouting = customRouting.compactMap { CourierUserPreferencesChannel.init(rawValue: $0 as! String) }
|
|
410
|
+
|
|
411
|
+
Task {
|
|
412
|
+
do {
|
|
413
|
+
try await client.preferences.putUserPreferenceTopic(
|
|
414
|
+
topicId: topicId,
|
|
415
|
+
status: CourierUserPreferencesStatus.init(rawValue: status) ?? .unknown,
|
|
416
|
+
hasCustomRouting: hasCustomRouting,
|
|
417
|
+
customRouting: customRouting
|
|
418
|
+
)
|
|
419
|
+
resolve(nil)
|
|
420
|
+
} catch {
|
|
421
|
+
Rejections.clientError(reject, error: error)
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
@objc(postTrackingUrl:withUrl:withEvent:withResolver:withRejecter:)
|
|
427
|
+
func postTrackingUrl(clientId: NSString, url: NSString, event: NSString, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
428
|
+
|
|
429
|
+
guard let client = clients[clientId as String] else {
|
|
430
|
+
Rejections.missingClient(reject)
|
|
431
|
+
return
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
let url = url as String
|
|
435
|
+
let event = event as String
|
|
436
|
+
|
|
437
|
+
Task {
|
|
438
|
+
do {
|
|
439
|
+
try await client.tracking.postTrackingUrl(
|
|
440
|
+
url: url,
|
|
441
|
+
event: CourierTrackingEvent(rawValue: event.uppercased()) ?? .clicked
|
|
442
|
+
)
|
|
443
|
+
resolve(nil)
|
|
444
|
+
} catch {
|
|
445
|
+
Rejections.clientError(reject, error: error)
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
}
|
|
@@ -42,17 +42,25 @@ class CourierInboxView : UIView {
|
|
|
42
42
|
lightTheme: lightTheme?.toInboxTheme() ?? .defaultLight,
|
|
43
43
|
darkTheme: darkTheme?.toInboxTheme() ?? .defaultDark,
|
|
44
44
|
didClickInboxMessageAtIndex: { [weak self] message, index in
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
do {
|
|
46
|
+
self?.onClickInboxMessageAtIndex?([
|
|
47
|
+
"message" : try message.toJson() ?? "",
|
|
48
|
+
"index" : index
|
|
49
|
+
])
|
|
50
|
+
} catch {
|
|
51
|
+
Courier.shared.client?.error(error.localizedDescription)
|
|
52
|
+
}
|
|
49
53
|
},
|
|
50
54
|
didClickInboxActionForMessageAtIndex: { [weak self] action, message, index in
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
do {
|
|
56
|
+
self?.onClickInboxActionForMessageAtIndex?([
|
|
57
|
+
"action" : try action.toJson() ?? "",
|
|
58
|
+
"message" : try message.toJson() ?? "",
|
|
59
|
+
"index" : index
|
|
60
|
+
])
|
|
61
|
+
} catch {
|
|
62
|
+
Courier.shared.client?.error(error.localizedDescription)
|
|
63
|
+
}
|
|
56
64
|
},
|
|
57
65
|
didScrollInbox: { [weak self] scrollView in
|
|
58
66
|
self?.onScrollInbox?([
|
|
@@ -57,13 +57,11 @@ NSUInteger notificationPresentationOptions = UNNotificationPresentationOptionNon
|
|
|
57
57
|
UNNotificationContent *content = notification.request.content;
|
|
58
58
|
NSDictionary *message = content.userInfo;
|
|
59
59
|
|
|
60
|
-
[
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
[self log:error];
|
|
60
|
+
[message trackMessageWithEvent:CourierTrackingEventDelivered completion:^(NSError * _Nullable error) {
|
|
61
|
+
if (error) {
|
|
62
|
+
NSLog(@"Error tracking message: %@", error.localizedDescription);
|
|
64
63
|
}
|
|
65
|
-
}
|
|
66
|
-
];
|
|
64
|
+
}];
|
|
67
65
|
|
|
68
66
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
69
67
|
|
|
@@ -82,50 +80,35 @@ NSUInteger notificationPresentationOptions = UNNotificationPresentationOptionNon
|
|
|
82
80
|
UNNotificationContent *content = response.notification.request.content;
|
|
83
81
|
NSDictionary *message = content.userInfo;
|
|
84
82
|
|
|
85
|
-
[
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
[self log:error];
|
|
83
|
+
[message trackMessageWithEvent:CourierTrackingEventClicked completion:^(NSError * _Nullable error) {
|
|
84
|
+
if (error) {
|
|
85
|
+
NSLog(@"Error tracking message: %@", error.localizedDescription);
|
|
89
86
|
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
87
|
+
}];
|
|
88
|
+
|
|
93
89
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
94
|
-
|
|
90
|
+
|
|
95
91
|
NSDictionary *pushNotification = [Courier formatPushNotificationWithContent:content];
|
|
96
92
|
[[NSNotificationCenter defaultCenter] postNotificationName:@"pushNotificationClicked" object:nil userInfo:pushNotification];
|
|
97
|
-
|
|
93
|
+
|
|
98
94
|
completionHandler();
|
|
99
|
-
|
|
95
|
+
|
|
100
96
|
});
|
|
101
97
|
|
|
102
98
|
}
|
|
103
99
|
|
|
104
100
|
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
|
|
105
101
|
{
|
|
106
|
-
|
|
102
|
+
NSLog(@"Failed to rgister for remote notification token: %@", error.localizedDescription);
|
|
107
103
|
}
|
|
108
104
|
|
|
109
105
|
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
|
|
110
106
|
{
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
// Empty
|
|
117
|
-
}
|
|
118
|
-
onFailure:^(NSError *error)
|
|
119
|
-
{
|
|
120
|
-
[self log:error];
|
|
121
|
-
}
|
|
122
|
-
];
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
- (void)log: (NSError*)error {
|
|
127
|
-
NSString *err = [NSString stringWithFormat:@"%@", error];
|
|
128
|
-
[Courier log:err];
|
|
107
|
+
[[Courier shared] setAPNSTokenWithRawToken:deviceToken completion:^(NSError * _Nullable error) {
|
|
108
|
+
if (error) {
|
|
109
|
+
NSLog(@"Error setting APNS Token: %@", error.localizedDescription);
|
|
110
|
+
}
|
|
111
|
+
}];
|
|
129
112
|
}
|
|
130
113
|
|
|
131
114
|
@end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//
|
|
2
|
+
// CourierReactNativeEventEmitter.swift
|
|
3
|
+
// courier-react-native
|
|
4
|
+
//
|
|
5
|
+
// Created by Michael Miller on 8/21/24.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Courier_iOS
|
|
9
|
+
|
|
10
|
+
internal class CourierReactNativeEventEmitter: RCTEventEmitter {
|
|
11
|
+
|
|
12
|
+
override init() {
|
|
13
|
+
super.init()
|
|
14
|
+
|
|
15
|
+
// Set the user agent
|
|
16
|
+
// Used to know the platform performing requests
|
|
17
|
+
Courier.agent = CourierAgent.react_native_ios
|
|
18
|
+
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@objc override static func requiresMainQueueSetup() -> Bool {
|
|
22
|
+
return true
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
}
|