@dashx/react-native 0.1.9 → 0.1.13
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 +7 -3
- package/android/src/main/AndroidManifest.xml +3 -3
- package/android/src/main/java/com/dashx/rn/sdk/DashXActivityLifecycleCallbacks.kt +5 -5
- package/android/src/main/java/com/dashx/rn/sdk/DashXClientInterceptor.kt +16 -14
- package/android/src/main/java/com/dashx/rn/sdk/DashXExceptionHandler.kt +8 -3
- package/android/src/main/java/com/dashx/rn/sdk/DashXMessagingService.kt +4 -1
- package/android/src/main/java/com/dashx/rn/sdk/DashXModule.kt +21 -16
- package/ios/API.swift +124 -18
- package/ios/Constants.swift +1 -0
- package/ios/DashX.m +1 -0
- package/ios/DashX.swift +5 -0
- package/ios/DashXClient.swift +42 -7
- package/ios/graphql/SubscribeContact.graphql +1 -0
- package/ios/schema.json +16026 -19786
- package/package.json +1 -1
package/android/build.gradle
CHANGED
|
@@ -90,15 +90,19 @@ repositories {
|
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
dependencies {
|
|
93
|
-
implementation 'com.github.dashxhq:dashx-android:
|
|
93
|
+
implementation 'com.github.dashxhq:dashx-android:main-SNAPSHOT'
|
|
94
94
|
//noinspection GradleDynamicVersion
|
|
95
95
|
implementation 'com.facebook.react:react-native:+' // From node_modules
|
|
96
96
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
|
97
97
|
|
|
98
98
|
implementation 'com.google.code.gson:gson:2.8.6'
|
|
99
99
|
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
// Import the Firebase BoM (see: https://firebase.google.com/docs/android/learn-more#bom)
|
|
101
|
+
implementation platform('com.google.firebase:firebase-bom:28.3.0')
|
|
102
|
+
implementation 'com.google.firebase:firebase-messaging-ktx'
|
|
103
|
+
|
|
104
|
+
// The Firebase SDK for Google Analytics is needed for delivery reports
|
|
105
|
+
implementation 'com.google.firebase:firebase-analytics-ktx'
|
|
102
106
|
}
|
|
103
107
|
|
|
104
108
|
def configureReactNativePom(def pom) {
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
package="com.dashx.rn.sdk">
|
|
3
3
|
|
|
4
4
|
<application>
|
|
5
|
-
<service android:name="
|
|
6
|
-
<intent-filter
|
|
7
|
-
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
|
|
5
|
+
<service android:name=".DashXMessagingService" android:exported="false">
|
|
6
|
+
<intent-filter>
|
|
7
|
+
<action android:name="com.google.firebase.MESSAGING_EVENT" />
|
|
8
8
|
</intent-filter>
|
|
9
9
|
</service>
|
|
10
10
|
</application>
|
|
@@ -12,7 +12,7 @@ class DashXActivityLifecycleCallbacks : Application.ActivityLifecycleCallbacks {
|
|
|
12
12
|
private var startSession = System.currentTimeMillis().toDouble()
|
|
13
13
|
|
|
14
14
|
init {
|
|
15
|
-
dashXClient
|
|
15
|
+
dashXClient?.trackAppStarted()
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
override fun onActivityPaused(activity: Activity) {
|
|
@@ -20,7 +20,7 @@ class DashXActivityLifecycleCallbacks : Application.ActivityLifecycleCallbacks {
|
|
|
20
20
|
return
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
dashXClient
|
|
23
|
+
dashXClient?.trackAppSession(System.currentTimeMillis().toDouble() - startSession)
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
override fun onActivityResumed(activity: Activity) {
|
|
@@ -29,7 +29,7 @@ class DashXActivityLifecycleCallbacks : Application.ActivityLifecycleCallbacks {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
startSession = System.currentTimeMillis().toDouble()
|
|
32
|
-
dashXClient
|
|
32
|
+
dashXClient?.trackAppStarted(fromBackground = true)
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
override fun onActivityStarted(activity: Activity) {
|
|
@@ -37,10 +37,10 @@ class DashXActivityLifecycleCallbacks : Application.ActivityLifecycleCallbacks {
|
|
|
37
37
|
return
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
val packageManager = activity
|
|
40
|
+
val packageManager = activity.packageManager
|
|
41
41
|
val info = packageManager?.getActivityInfo(activity.componentName, PackageManager.GET_META_DATA)
|
|
42
42
|
val activityLabel = info?.loadLabel(packageManager)
|
|
43
|
-
activityLabel?.let { it -> dashXClient
|
|
43
|
+
activityLabel?.let { it -> dashXClient?.screen(it.toString(), hashMapOf()) }
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
override fun onActivityDestroyed(activity: Activity) {
|
|
@@ -16,35 +16,37 @@ class DashXClientInterceptor private constructor() {
|
|
|
16
16
|
|
|
17
17
|
fun createDashXClient(reactApplicationContext: ReactApplicationContext, publicKey: String, baseURI: String?, targetEnvironment: String?, targetInstallation: String?) {
|
|
18
18
|
this.reactApplicationContext = reactApplicationContext
|
|
19
|
-
client = DashX(reactApplicationContext.applicationContext, publicKey
|
|
19
|
+
client = DashX(reactApplicationContext.applicationContext, publicKey, baseURI, targetEnvironment, targetInstallation)
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
fun getDashXClient(): com.dashx.sdk.DashXClient {
|
|
23
|
-
|
|
24
|
-
throw Exception("DashXClient not initialised")
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return client!!
|
|
22
|
+
fun getDashXClient(): com.dashx.sdk.DashXClient? {
|
|
23
|
+
return client
|
|
28
24
|
}
|
|
29
25
|
|
|
30
26
|
fun handleMessage(remoteMessage: RemoteMessage) {
|
|
31
|
-
val
|
|
27
|
+
val notificationData = remoteMessage.getData()
|
|
28
|
+
|
|
29
|
+
DashXLog.d(tag, "Notification Data: " + notificationData)
|
|
30
|
+
|
|
32
31
|
val eventProperties: WritableMap = Arguments.createMap()
|
|
33
|
-
DashXLog.d(tag, "Data: " + remoteMessage.data)
|
|
34
32
|
|
|
35
33
|
try {
|
|
36
|
-
eventProperties.putMap("data", convertToWritableMap(
|
|
34
|
+
eventProperties.putMap("data", convertToWritableMap(notificationData, listOf(dashXNotificationFilter)))
|
|
37
35
|
} catch (e: Exception) {
|
|
38
|
-
DashXLog.d(tag, "Encountered an error while parsing notification data")
|
|
39
36
|
e.printStackTrace()
|
|
37
|
+
DashXLog.d(tag, "Encountered an error while parsing notification data.")
|
|
40
38
|
}
|
|
41
39
|
|
|
40
|
+
val notification = remoteMessage.getNotification()
|
|
41
|
+
|
|
42
42
|
if (notification != null) {
|
|
43
43
|
val notificationProperties: WritableMap = Arguments.createMap()
|
|
44
|
-
notificationProperties.putString("title", notification.
|
|
45
|
-
notificationProperties.putString("body", notification.
|
|
44
|
+
notificationProperties.putString("title", notification.getTitle())
|
|
45
|
+
notificationProperties.putString("body", notification.getBody())
|
|
46
|
+
|
|
46
47
|
eventProperties.putMap("notification", notificationProperties)
|
|
47
|
-
|
|
48
|
+
|
|
49
|
+
DashXLog.d(tag, "onMessageReceived with Title: " + notification.getTitle() + " and Body: " + notification.getBody())
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
sendJsEvent("messageReceived", eventProperties)
|
|
@@ -11,13 +11,18 @@ class DashXExceptionHandler(private val mainExceptionHandler: Thread.UncaughtExc
|
|
|
11
11
|
return
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
if (defaultExceptionHandler != null) {
|
|
15
|
+
val dashXExceptionHandler = DashXExceptionHandler(defaultExceptionHandler)
|
|
16
|
+
Thread.setDefaultUncaughtExceptionHandler(dashXExceptionHandler)
|
|
17
|
+
}
|
|
16
18
|
}
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
override fun uncaughtException(thread: Thread, exception: Throwable) {
|
|
20
|
-
dashXClient
|
|
22
|
+
if (dashXClient != null) {
|
|
23
|
+
dashXClient.trackAppCrashed(exception)
|
|
24
|
+
}
|
|
25
|
+
|
|
21
26
|
mainExceptionHandler.uncaughtException(thread, exception)
|
|
22
27
|
}
|
|
23
28
|
}
|
|
@@ -10,8 +10,11 @@ class DashXMessagingService : FirebaseMessagingService() {
|
|
|
10
10
|
|
|
11
11
|
override fun onNewToken(token: String) {
|
|
12
12
|
super.onNewToken(token)
|
|
13
|
-
dashXClient.setDeviceToken(token)
|
|
14
13
|
DashXLog.d(tag, "onNewToken: $token")
|
|
14
|
+
|
|
15
|
+
if (dashXClient != null) {
|
|
16
|
+
dashXClient.setDeviceToken(token)
|
|
17
|
+
}
|
|
15
18
|
}
|
|
16
19
|
|
|
17
20
|
override fun onMessageReceived(remoteMessage: RemoteMessage) {
|
|
@@ -3,7 +3,7 @@ package com.dashx.rn.sdk
|
|
|
3
3
|
import com.facebook.react.bridge.*
|
|
4
4
|
import com.dashx.sdk.DashXLog
|
|
5
5
|
import com.google.android.gms.tasks.OnCompleteListener
|
|
6
|
-
import com.google.firebase.
|
|
6
|
+
import com.google.firebase.messaging.FirebaseMessaging
|
|
7
7
|
|
|
8
8
|
class DashXModule(private val reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
|
|
9
9
|
private val tag = DashXModule::class.java.simpleName
|
|
@@ -28,7 +28,7 @@ class DashXModule(private val reactContext: ReactApplicationContext) : ReactCont
|
|
|
28
28
|
options.getStringIfPresent("targetEnvironment"),
|
|
29
29
|
options.getStringIfPresent("targetInstallation")
|
|
30
30
|
)
|
|
31
|
-
interceptor.getDashXClient()
|
|
31
|
+
interceptor.getDashXClient()?.generateAnonymousUid()
|
|
32
32
|
|
|
33
33
|
if (options.hasKey("trackAppLifecycleEvents") && options.getBoolean("trackAppLifecycleEvents")) {
|
|
34
34
|
DashXExceptionHandler.enable()
|
|
@@ -39,28 +39,28 @@ class DashXModule(private val reactContext: ReactApplicationContext) : ReactCont
|
|
|
39
39
|
DashXActivityLifecycleCallbacks.enableScreenTracking(reactContext.applicationContext)
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
FirebaseMessaging.getInstance().getToken()
|
|
43
43
|
.addOnCompleteListener(OnCompleteListener { task ->
|
|
44
44
|
if (!task.isSuccessful) {
|
|
45
|
-
DashXLog.d(tag, "
|
|
45
|
+
DashXLog.d(tag, "FirebaseMessaging.getInstance().getToken() failed: $task.exception")
|
|
46
46
|
return@OnCompleteListener
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
val token = task.
|
|
50
|
-
token?.let { it -> interceptor.getDashXClient()
|
|
49
|
+
val token = task.getResult()
|
|
50
|
+
token?.let { it -> interceptor.getDashXClient()?.setDeviceToken(it) }
|
|
51
51
|
DashXLog.d(tag, "Firebase Initialised with: $token")
|
|
52
|
-
})
|
|
52
|
+
});
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
@ReactMethod
|
|
56
56
|
fun identify(uid: String?, options: ReadableMap?) {
|
|
57
57
|
val optionsHashMap = options?.toHashMap()
|
|
58
|
-
interceptor.getDashXClient()
|
|
58
|
+
interceptor.getDashXClient()?.identify(uid, optionsHashMap as HashMap<String, String>?)
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
@ReactMethod
|
|
62
62
|
fun reset() {
|
|
63
|
-
interceptor.getDashXClient()
|
|
63
|
+
interceptor.getDashXClient()?.reset()
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
@ReactMethod
|
|
@@ -72,22 +72,22 @@ class DashXModule(private val reactContext: ReactApplicationContext) : ReactCont
|
|
|
72
72
|
return
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
interceptor.getDashXClient()
|
|
75
|
+
interceptor.getDashXClient()?.track(event, jsonData)
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
@ReactMethod
|
|
79
79
|
fun screen(screenName: String, data: ReadableMap?) {
|
|
80
|
-
interceptor.getDashXClient()
|
|
80
|
+
interceptor.getDashXClient()?.screen(screenName, data?.toHashMap() as HashMap<String, String>)
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
@ReactMethod
|
|
84
84
|
fun setIdentityToken(identityToken: String) {
|
|
85
|
-
interceptor.getDashXClient()
|
|
85
|
+
interceptor.getDashXClient()?.setIdentityToken(identityToken)
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
@ReactMethod
|
|
89
89
|
fun fetchContent(urn: String, options: ReadableMap?, promise: Promise) {
|
|
90
|
-
interceptor.getDashXClient()
|
|
90
|
+
interceptor.getDashXClient()?.fetchContent(
|
|
91
91
|
urn,
|
|
92
92
|
options?.getBooleanIfPresent("preview"),
|
|
93
93
|
options?.getStringIfPresent("language"),
|
|
@@ -119,7 +119,7 @@ class DashXModule(private val reactContext: ReactApplicationContext) : ReactCont
|
|
|
119
119
|
throw Exception("Encountered an error while parsing order")
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
interceptor.getDashXClient()
|
|
122
|
+
interceptor.getDashXClient()?.searchContent(
|
|
123
123
|
contentType,
|
|
124
124
|
options?.getString("returnType") ?: "all",
|
|
125
125
|
jsonFilter,
|
|
@@ -159,7 +159,7 @@ class DashXModule(private val reactContext: ReactApplicationContext) : ReactCont
|
|
|
159
159
|
throw Exception("Encountered an error while parsing custom")
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
-
interceptor.getDashXClient()
|
|
162
|
+
interceptor.getDashXClient()?.addItemToCart(
|
|
163
163
|
itemId,
|
|
164
164
|
pricingId,
|
|
165
165
|
quantity,
|
|
@@ -176,7 +176,7 @@ class DashXModule(private val reactContext: ReactApplicationContext) : ReactCont
|
|
|
176
176
|
|
|
177
177
|
@ReactMethod
|
|
178
178
|
fun fetchCart(promise: Promise) {
|
|
179
|
-
interceptor.getDashXClient()
|
|
179
|
+
interceptor.getDashXClient()?.fetchCart(
|
|
180
180
|
onError = {
|
|
181
181
|
promise.reject("EUNSPECIFIED", it)
|
|
182
182
|
},
|
|
@@ -185,4 +185,9 @@ class DashXModule(private val reactContext: ReactApplicationContext) : ReactCont
|
|
|
185
185
|
}
|
|
186
186
|
)
|
|
187
187
|
}
|
|
188
|
+
|
|
189
|
+
@ReactMethod
|
|
190
|
+
fun subscribe() {
|
|
191
|
+
interceptor.getDashXClient()?.subscribe()
|
|
192
|
+
}
|
|
188
193
|
}
|
package/ios/API.swift
CHANGED
|
@@ -553,20 +553,38 @@ public enum DashXGql {
|
|
|
553
553
|
public var graphQLMap: GraphQLMap
|
|
554
554
|
|
|
555
555
|
/// - Parameters:
|
|
556
|
-
/// -
|
|
556
|
+
/// - accountUid
|
|
557
|
+
/// - accountAnonymousUid
|
|
557
558
|
/// - name
|
|
558
559
|
/// - kind
|
|
559
560
|
/// - value
|
|
560
|
-
|
|
561
|
-
|
|
561
|
+
/// - userAgent
|
|
562
|
+
/// - osName
|
|
563
|
+
/// - osVersion
|
|
564
|
+
/// - deviceModel
|
|
565
|
+
/// - deviceManufacturer
|
|
566
|
+
/// - deviceUid
|
|
567
|
+
/// - deviceAdvertisingUid
|
|
568
|
+
/// - isDeviceAdTrackingEnabled
|
|
569
|
+
public init(accountUid: Swift.Optional<String?> = nil, accountAnonymousUid: Swift.Optional<String?> = nil, name: Swift.Optional<String?> = nil, kind: ContactKind, value: String, userAgent: Swift.Optional<String?> = nil, osName: Swift.Optional<String?> = nil, osVersion: Swift.Optional<String?> = nil, deviceModel: Swift.Optional<String?> = nil, deviceManufacturer: Swift.Optional<String?> = nil, deviceUid: Swift.Optional<String?> = nil, deviceAdvertisingUid: Swift.Optional<String?> = nil, isDeviceAdTrackingEnabled: Swift.Optional<Bool?> = nil) {
|
|
570
|
+
graphQLMap = ["accountUid": accountUid, "accountAnonymousUid": accountAnonymousUid, "name": name, "kind": kind, "value": value, "userAgent": userAgent, "osName": osName, "osVersion": osVersion, "deviceModel": deviceModel, "deviceManufacturer": deviceManufacturer, "deviceUid": deviceUid, "deviceAdvertisingUid": deviceAdvertisingUid, "isDeviceAdTrackingEnabled": isDeviceAdTrackingEnabled]
|
|
562
571
|
}
|
|
563
572
|
|
|
564
|
-
public var
|
|
573
|
+
public var accountUid: Swift.Optional<String?> {
|
|
565
574
|
get {
|
|
566
|
-
return graphQLMap["
|
|
575
|
+
return graphQLMap["accountUid"] as? Swift.Optional<String?> ?? Swift.Optional<String?>.none
|
|
567
576
|
}
|
|
568
577
|
set {
|
|
569
|
-
graphQLMap.updateValue(newValue, forKey: "
|
|
578
|
+
graphQLMap.updateValue(newValue, forKey: "accountUid")
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
public var accountAnonymousUid: Swift.Optional<String?> {
|
|
583
|
+
get {
|
|
584
|
+
return graphQLMap["accountAnonymousUid"] as? Swift.Optional<String?> ?? Swift.Optional<String?>.none
|
|
585
|
+
}
|
|
586
|
+
set {
|
|
587
|
+
graphQLMap.updateValue(newValue, forKey: "accountAnonymousUid")
|
|
570
588
|
}
|
|
571
589
|
}
|
|
572
590
|
|
|
@@ -596,43 +614,119 @@ public enum DashXGql {
|
|
|
596
614
|
graphQLMap.updateValue(newValue, forKey: "value")
|
|
597
615
|
}
|
|
598
616
|
}
|
|
617
|
+
|
|
618
|
+
public var userAgent: Swift.Optional<String?> {
|
|
619
|
+
get {
|
|
620
|
+
return graphQLMap["userAgent"] as? Swift.Optional<String?> ?? Swift.Optional<String?>.none
|
|
621
|
+
}
|
|
622
|
+
set {
|
|
623
|
+
graphQLMap.updateValue(newValue, forKey: "userAgent")
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
public var osName: Swift.Optional<String?> {
|
|
628
|
+
get {
|
|
629
|
+
return graphQLMap["osName"] as? Swift.Optional<String?> ?? Swift.Optional<String?>.none
|
|
630
|
+
}
|
|
631
|
+
set {
|
|
632
|
+
graphQLMap.updateValue(newValue, forKey: "osName")
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
public var osVersion: Swift.Optional<String?> {
|
|
637
|
+
get {
|
|
638
|
+
return graphQLMap["osVersion"] as? Swift.Optional<String?> ?? Swift.Optional<String?>.none
|
|
639
|
+
}
|
|
640
|
+
set {
|
|
641
|
+
graphQLMap.updateValue(newValue, forKey: "osVersion")
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
public var deviceModel: Swift.Optional<String?> {
|
|
646
|
+
get {
|
|
647
|
+
return graphQLMap["deviceModel"] as? Swift.Optional<String?> ?? Swift.Optional<String?>.none
|
|
648
|
+
}
|
|
649
|
+
set {
|
|
650
|
+
graphQLMap.updateValue(newValue, forKey: "deviceModel")
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
public var deviceManufacturer: Swift.Optional<String?> {
|
|
655
|
+
get {
|
|
656
|
+
return graphQLMap["deviceManufacturer"] as? Swift.Optional<String?> ?? Swift.Optional<String?>.none
|
|
657
|
+
}
|
|
658
|
+
set {
|
|
659
|
+
graphQLMap.updateValue(newValue, forKey: "deviceManufacturer")
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
public var deviceUid: Swift.Optional<String?> {
|
|
664
|
+
get {
|
|
665
|
+
return graphQLMap["deviceUid"] as? Swift.Optional<String?> ?? Swift.Optional<String?>.none
|
|
666
|
+
}
|
|
667
|
+
set {
|
|
668
|
+
graphQLMap.updateValue(newValue, forKey: "deviceUid")
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
public var deviceAdvertisingUid: Swift.Optional<String?> {
|
|
673
|
+
get {
|
|
674
|
+
return graphQLMap["deviceAdvertisingUid"] as? Swift.Optional<String?> ?? Swift.Optional<String?>.none
|
|
675
|
+
}
|
|
676
|
+
set {
|
|
677
|
+
graphQLMap.updateValue(newValue, forKey: "deviceAdvertisingUid")
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
public var isDeviceAdTrackingEnabled: Swift.Optional<Bool?> {
|
|
682
|
+
get {
|
|
683
|
+
return graphQLMap["isDeviceAdTrackingEnabled"] as? Swift.Optional<Bool?> ?? Swift.Optional<Bool?>.none
|
|
684
|
+
}
|
|
685
|
+
set {
|
|
686
|
+
graphQLMap.updateValue(newValue, forKey: "isDeviceAdTrackingEnabled")
|
|
687
|
+
}
|
|
688
|
+
}
|
|
599
689
|
}
|
|
600
690
|
|
|
601
691
|
public enum ContactKind: RawRepresentable, Equatable, Hashable, CaseIterable, Apollo.JSONDecodable, Apollo.JSONEncodable {
|
|
602
692
|
public typealias RawValue = String
|
|
603
|
-
case
|
|
604
|
-
case
|
|
693
|
+
case email
|
|
694
|
+
case phone
|
|
605
695
|
case ios
|
|
606
696
|
case android
|
|
697
|
+
case web
|
|
607
698
|
/// Auto generated constant for unknown enum values
|
|
608
699
|
case __unknown(RawValue)
|
|
609
700
|
|
|
610
701
|
public init?(rawValue: RawValue) {
|
|
611
702
|
switch rawValue {
|
|
612
|
-
case "
|
|
613
|
-
case "
|
|
703
|
+
case "EMAIL": self = .email
|
|
704
|
+
case "PHONE": self = .phone
|
|
614
705
|
case "IOS": self = .ios
|
|
615
706
|
case "ANDROID": self = .android
|
|
707
|
+
case "WEB": self = .web
|
|
616
708
|
default: self = .__unknown(rawValue)
|
|
617
709
|
}
|
|
618
710
|
}
|
|
619
711
|
|
|
620
712
|
public var rawValue: RawValue {
|
|
621
713
|
switch self {
|
|
622
|
-
case .
|
|
623
|
-
case .
|
|
714
|
+
case .email: return "EMAIL"
|
|
715
|
+
case .phone: return "PHONE"
|
|
624
716
|
case .ios: return "IOS"
|
|
625
717
|
case .android: return "ANDROID"
|
|
718
|
+
case .web: return "WEB"
|
|
626
719
|
case .__unknown(let value): return value
|
|
627
720
|
}
|
|
628
721
|
}
|
|
629
722
|
|
|
630
723
|
public static func == (lhs: ContactKind, rhs: ContactKind) -> Bool {
|
|
631
724
|
switch (lhs, rhs) {
|
|
632
|
-
case (.
|
|
633
|
-
case (.
|
|
725
|
+
case (.email, .email): return true
|
|
726
|
+
case (.phone, .phone): return true
|
|
634
727
|
case (.ios, .ios): return true
|
|
635
728
|
case (.android, .android): return true
|
|
729
|
+
case (.web, .web): return true
|
|
636
730
|
case (.__unknown(let lhsValue), .__unknown(let rhsValue)): return lhsValue == rhsValue
|
|
637
731
|
default: return false
|
|
638
732
|
}
|
|
@@ -640,10 +734,11 @@ public enum DashXGql {
|
|
|
640
734
|
|
|
641
735
|
public static var allCases: [ContactKind] {
|
|
642
736
|
return [
|
|
643
|
-
.
|
|
644
|
-
.
|
|
737
|
+
.email,
|
|
738
|
+
.phone,
|
|
645
739
|
.ios,
|
|
646
740
|
.android,
|
|
741
|
+
.web,
|
|
647
742
|
]
|
|
648
743
|
}
|
|
649
744
|
}
|
|
@@ -2074,6 +2169,7 @@ public enum DashXGql {
|
|
|
2074
2169
|
subscribeContact(input: $input) {
|
|
2075
2170
|
__typename
|
|
2076
2171
|
id
|
|
2172
|
+
value
|
|
2077
2173
|
}
|
|
2078
2174
|
}
|
|
2079
2175
|
"""
|
|
@@ -2125,6 +2221,7 @@ public enum DashXGql {
|
|
|
2125
2221
|
return [
|
|
2126
2222
|
GraphQLField("__typename", type: .nonNull(.scalar(String.self))),
|
|
2127
2223
|
GraphQLField("id", type: .nonNull(.scalar(UUID.self))),
|
|
2224
|
+
GraphQLField("value", type: .nonNull(.scalar(String.self))),
|
|
2128
2225
|
]
|
|
2129
2226
|
}
|
|
2130
2227
|
|
|
@@ -2134,8 +2231,8 @@ public enum DashXGql {
|
|
|
2134
2231
|
self.resultMap = unsafeResultMap
|
|
2135
2232
|
}
|
|
2136
2233
|
|
|
2137
|
-
public init(id: UUID) {
|
|
2138
|
-
self.init(unsafeResultMap: ["__typename": "Contact", "id": id])
|
|
2234
|
+
public init(id: UUID, value: String) {
|
|
2235
|
+
self.init(unsafeResultMap: ["__typename": "Contact", "id": id, "value": value])
|
|
2139
2236
|
}
|
|
2140
2237
|
|
|
2141
2238
|
public var __typename: String {
|
|
@@ -2155,6 +2252,15 @@ public enum DashXGql {
|
|
|
2155
2252
|
resultMap.updateValue(newValue, forKey: "id")
|
|
2156
2253
|
}
|
|
2157
2254
|
}
|
|
2255
|
+
|
|
2256
|
+
public var value: String {
|
|
2257
|
+
get {
|
|
2258
|
+
return resultMap["value"]! as! String
|
|
2259
|
+
}
|
|
2260
|
+
set {
|
|
2261
|
+
resultMap.updateValue(newValue, forKey: "value")
|
|
2262
|
+
}
|
|
2263
|
+
}
|
|
2158
2264
|
}
|
|
2159
2265
|
}
|
|
2160
2266
|
}
|
package/ios/Constants.swift
CHANGED
|
@@ -3,6 +3,7 @@ import Foundation
|
|
|
3
3
|
struct Constants {
|
|
4
4
|
static let PACKAGE_NAME = "com.dashx.sdk"
|
|
5
5
|
static let USER_PREFERENCES_KEY_ANONYMOUS_UID = "\(PACKAGE_NAME).anonymous_uid"
|
|
6
|
+
static let USER_PREFERENCES_KEY_DEVICE_TOKEN = "\(PACKAGE_NAME).device_token"
|
|
6
7
|
static let USER_PREFERENCES_KEY_BUILD = "\(PACKAGE_NAME).build"
|
|
7
8
|
static let INTERNAL_EVENT_APP_INSTALLED = "Application Installed"
|
|
8
9
|
static let INTERNAL_EVENT_APP_UPDATED = "Application Updated"
|
package/ios/DashX.m
CHANGED
|
@@ -12,4 +12,5 @@ RCT_EXTERN_METHOD(searchContent:(NSString *)contentType options:(NSDictionary *)
|
|
|
12
12
|
RCT_EXTERN_METHOD(fetchContent:(NSString *)urn options:(NSDictionary *)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
|
|
13
13
|
RCT_EXTERN_METHOD(addItemToCart:(NSString *)itemId pricingId:(NSString *)pricingId quantity:(NSString *)quantity reset:(BOOL)reset custom:(NSDictionary *)custom resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
|
|
14
14
|
RCT_EXTERN_METHOD(fetchCart:resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
|
|
15
|
+
RCT_EXTERN_METHOD(subscribe)
|
|
15
16
|
@end
|
package/ios/DashX.swift
CHANGED
package/ios/DashXClient.swift
CHANGED
|
@@ -11,12 +11,18 @@ class DashXClient {
|
|
|
11
11
|
private var uid: String?
|
|
12
12
|
private var deviceToken: String?
|
|
13
13
|
|
|
14
|
+
private var mustSubscribe: Bool = false;
|
|
15
|
+
|
|
14
16
|
private init() {
|
|
15
17
|
generateAnonymousUid()
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
func setDeviceToken(to: String) {
|
|
19
21
|
self.deviceToken = to
|
|
22
|
+
|
|
23
|
+
if (self.mustSubscribe) {
|
|
24
|
+
self.subscribe()
|
|
25
|
+
}
|
|
20
26
|
}
|
|
21
27
|
|
|
22
28
|
func setTargetEnvironment(to: String) {
|
|
@@ -91,7 +97,7 @@ class DashXClient {
|
|
|
91
97
|
event: event,
|
|
92
98
|
accountUid: uid,
|
|
93
99
|
accountAnonymousUid: anonymousUid,
|
|
94
|
-
data: withData as? [String:
|
|
100
|
+
data: withData as? [String: JSONDecodable?]
|
|
95
101
|
)
|
|
96
102
|
|
|
97
103
|
DashXLog.d(tag: #function, "Calling track with \(trackEventInput)")
|
|
@@ -113,20 +119,46 @@ class DashXClient {
|
|
|
113
119
|
|
|
114
120
|
track(Constants.INTERNAL_EVENT_APP_SCREEN_VIEWED, withData: properties?.merging([ "name": screenName], uniquingKeysWith: { (_, new) in new }) as NSDictionary?)
|
|
115
121
|
}
|
|
122
|
+
|
|
123
|
+
// https://stackoverflow.com/a/11197770
|
|
124
|
+
func getDeviceModel() -> String {
|
|
125
|
+
var systemInfo = utsname()
|
|
126
|
+
uname(&systemInfo)
|
|
127
|
+
let machineMirror = Mirror(reflecting: systemInfo.machine)
|
|
128
|
+
return machineMirror.children.reduce("") { identifier, element in
|
|
129
|
+
guard let value = element.value as? Int8, value != 0 else { return identifier }
|
|
130
|
+
return identifier + String(UnicodeScalar(UInt8(value)))
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
116
134
|
// MARK: -- subscribe
|
|
117
135
|
|
|
118
136
|
func subscribe() {
|
|
119
|
-
if deviceToken == nil
|
|
137
|
+
if deviceToken == nil {
|
|
138
|
+
self.mustSubscribe = true
|
|
120
139
|
return
|
|
121
140
|
}
|
|
122
141
|
|
|
123
|
-
|
|
142
|
+
self.mustSubscribe = false
|
|
143
|
+
|
|
144
|
+
let preferences = UserDefaults.standard
|
|
145
|
+
let deviceTokenKey = Constants.USER_PREFERENCES_KEY_DEVICE_TOKEN
|
|
124
146
|
|
|
147
|
+
if preferences.string(forKey: deviceTokenKey) == deviceToken {
|
|
148
|
+
DashXLog.d(tag: #function, "Already subscribed: \(String(describing: deviceToken))")
|
|
149
|
+
return
|
|
150
|
+
}
|
|
151
|
+
|
|
125
152
|
let subscribeContactInput = DashXGql.SubscribeContactInput(
|
|
126
|
-
|
|
127
|
-
|
|
153
|
+
accountUid: uid,
|
|
154
|
+
accountAnonymousUid: anonymousUid!,
|
|
155
|
+
name: UIDevice.current.model,
|
|
128
156
|
kind: .ios,
|
|
129
|
-
value: deviceToken
|
|
157
|
+
value: deviceToken!,
|
|
158
|
+
osName: UIDevice.current.systemName,
|
|
159
|
+
osVersion: UIDevice.current.systemVersion,
|
|
160
|
+
deviceModel: getDeviceModel(),
|
|
161
|
+
deviceManufacturer: "Apple"
|
|
130
162
|
)
|
|
131
163
|
|
|
132
164
|
DashXLog.d(tag: #function, "Calling subscribe with \(subscribeContactInput)")
|
|
@@ -136,7 +168,10 @@ class DashXClient {
|
|
|
136
168
|
Network.shared.apollo.perform(mutation: subscribeContactMutation) { result in
|
|
137
169
|
switch result {
|
|
138
170
|
case .success(let graphQLResult):
|
|
139
|
-
|
|
171
|
+
if graphQLResult.data != nil {
|
|
172
|
+
preferences.set(graphQLResult.data?.subscribeContact.value, forKey: deviceTokenKey)
|
|
173
|
+
DashXLog.d(tag: #function, "Sent subscribe with \(String(describing: graphQLResult))")
|
|
174
|
+
}
|
|
140
175
|
case .failure(let error):
|
|
141
176
|
DashXLog.d(tag: #function, "Encountered an error during subscribe(): \(error)")
|
|
142
177
|
}
|