hypertrack-sdk-react-native 13.4.0 → 13.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/android/gradle.properties +1 -1
  2. package/android/src/main/java/com/reactnativehypertracksdk/HyperTrackReactNativePlugin.kt +72 -37
  3. package/android/src/main/java/com/reactnativehypertracksdk/HyperTrackSdkPackage.kt +3 -6
  4. package/android/src/main/java/com/reactnativehypertracksdk/ReactNativeSerialization.kt +2 -3
  5. package/android/src/main/java/com/reactnativehypertracksdk/common/HyperTrackSdkWrapper.kt +46 -62
  6. package/android/src/main/java/com/reactnativehypertracksdk/common/SdkMethod.kt +1 -0
  7. package/android/src/main/java/com/reactnativehypertracksdk/common/Serialization.kt +115 -113
  8. package/android/src/main/java/com/reactnativehypertracksdk/common/WrapperResult.kt +14 -14
  9. package/hypertrack-sdk-react-native.podspec +1 -1
  10. package/ios/HyperTrackReactNativePlugin.m +4 -1
  11. package/ios/HyperTrackReactNativePlugin.swift +21 -1
  12. package/ios/common/HyperTrackSDKWrapper.swift +4 -0
  13. package/ios/common/SDKMethod.swift +1 -0
  14. package/ios/common/Serialization.swift +30 -0
  15. package/lib/commonjs/HyperTrack/HyperTrack.js +72 -1
  16. package/lib/commonjs/HyperTrack/HyperTrack.js.map +1 -1
  17. package/lib/commonjs/HyperTrack/data_types/Order.js +6 -0
  18. package/lib/commonjs/HyperTrack/data_types/Order.js.map +1 -0
  19. package/lib/commonjs/HyperTrack/data_types/internal/IsInsideGeofence.js +2 -0
  20. package/lib/commonjs/HyperTrack/data_types/internal/IsInsideGeofence.js.map +1 -0
  21. package/lib/commonjs/HyperTrack/data_types/internal/OrderInternal.js +6 -0
  22. package/lib/commonjs/HyperTrack/data_types/internal/OrderInternal.js.map +1 -0
  23. package/lib/commonjs/HyperTrack/data_types/internal/OrdersInternal.js +2 -0
  24. package/lib/commonjs/HyperTrack/data_types/internal/OrdersInternal.js.map +1 -0
  25. package/lib/commonjs/index.js +0 -66
  26. package/lib/commonjs/index.js.map +1 -1
  27. package/lib/module/HyperTrack/HyperTrack.js +72 -1
  28. package/lib/module/HyperTrack/HyperTrack.js.map +1 -1
  29. package/lib/module/HyperTrack/data_types/Order.js +2 -0
  30. package/lib/module/HyperTrack/data_types/Order.js.map +1 -0
  31. package/lib/module/HyperTrack/data_types/internal/IsInsideGeofence.js +2 -0
  32. package/lib/module/HyperTrack/data_types/internal/IsInsideGeofence.js.map +1 -0
  33. package/lib/module/HyperTrack/data_types/internal/OrderInternal.js +2 -0
  34. package/lib/module/HyperTrack/data_types/internal/OrderInternal.js.map +1 -0
  35. package/lib/module/HyperTrack/data_types/internal/OrdersInternal.js +2 -0
  36. package/lib/module/HyperTrack/data_types/internal/OrdersInternal.js.map +1 -0
  37. package/lib/module/index.js +0 -6
  38. package/lib/module/index.js.map +1 -1
  39. package/lib/typescript/HyperTrack/HyperTrack.d.ts +30 -2
  40. package/lib/typescript/HyperTrack/data_types/Order.d.ts +6 -0
  41. package/lib/typescript/HyperTrack/data_types/internal/IsInsideGeofence.d.ts +4 -0
  42. package/lib/typescript/HyperTrack/data_types/internal/OrderInternal.d.ts +8 -0
  43. package/lib/typescript/HyperTrack/data_types/internal/OrdersInternal.d.ts +4 -0
  44. package/lib/typescript/index.d.ts +7 -6
  45. package/package.json +2 -2
  46. package/src/HyperTrack/HyperTrack.ts +89 -2
  47. package/src/HyperTrack/data_types/Order.ts +7 -0
  48. package/src/HyperTrack/data_types/internal/IsInsideGeofence.ts +4 -0
  49. package/src/HyperTrack/data_types/internal/OrderInternal.ts +9 -0
  50. package/src/HyperTrack/data_types/internal/OrdersInternal.ts +4 -0
  51. package/src/index.tsx +10 -7
@@ -1,3 +1,3 @@
1
1
  HyperTrackSdk_kotlinVersion=1.6.21
2
- HyperTrackSdk_HyperTrackSDKVersion=7.6.0
2
+ HyperTrackSdk_HyperTrackSDKVersion=7.7.0
3
3
  android.useAndroidX=true
@@ -1,26 +1,32 @@
1
1
  package com.reactnativehypertracksdk
2
2
 
3
- import com.facebook.react.bridge.*
3
+ import com.facebook.react.bridge.Promise
4
+ import com.facebook.react.bridge.ReactApplicationContext
5
+ import com.facebook.react.bridge.ReactContextBaseJavaModule
6
+ import com.facebook.react.bridge.ReactMethod
7
+ import com.facebook.react.bridge.ReadableMap
8
+ import com.facebook.react.bridge.WritableArray
9
+ import com.facebook.react.bridge.WritableMap
4
10
  import com.facebook.react.module.annotations.ReactModule
5
11
  import com.facebook.react.modules.core.DeviceEventManagerModule
6
- import com.hypertrack.sdk.*
7
12
  import com.hypertrack.sdk.android.HyperTrack
8
- import com.reactnativehypertracksdk.common.*
13
+ import com.reactnativehypertracksdk.common.HyperTrackSdkWrapper
9
14
  import com.reactnativehypertracksdk.common.Serialization.serializeErrors
10
15
  import com.reactnativehypertracksdk.common.Serialization.serializeIsAvailable
11
16
  import com.reactnativehypertracksdk.common.Serialization.serializeIsTracking
12
17
  import com.reactnativehypertracksdk.common.Serialization.serializeLocateResult
13
18
  import com.reactnativehypertracksdk.common.Serialization.serializeLocationResult
19
+ import com.reactnativehypertracksdk.common.Serialization.serializeOrders
20
+ import com.reactnativehypertracksdk.common.Success
14
21
 
15
22
  @ReactModule(name = HyperTrackReactNativePlugin.NAME)
16
- class HyperTrackReactNativePlugin(reactContext: ReactApplicationContext?) :
17
- ReactContextBaseJavaModule(reactContext) {
23
+ class HyperTrackReactNativePlugin(
24
+ reactContext: ReactApplicationContext?,
25
+ ) : ReactContextBaseJavaModule(reactContext) {
18
26
  private var locateSubscription: HyperTrack.Cancellable? = null
19
27
  private var subscriptions: List<HyperTrack.Cancellable>? = null
20
28
 
21
- override fun getName(): String {
22
- return NAME
23
- }
29
+ override fun getName(): String = NAME
24
30
 
25
31
  /**
26
32
  * ReactNative built-in methods
@@ -40,15 +46,28 @@ class HyperTrackReactNativePlugin(reactContext: ReactApplicationContext?) :
40
46
  EVENT_ERRORS -> {
41
47
  emitEvent(EVENT_ERRORS, serializeErrors(HyperTrack.errors).toWriteableArray())
42
48
  }
49
+
43
50
  EVENT_IS_AVAILABLE -> {
44
- emitEvent(EVENT_IS_AVAILABLE, serializeIsAvailable(HyperTrack.isAvailable).toWritableMap())
51
+ emitEvent(
52
+ EVENT_IS_AVAILABLE,
53
+ serializeIsAvailable(HyperTrack.isAvailable).toWritableMap(),
54
+ )
45
55
  }
56
+
46
57
  EVENT_IS_TRACKING -> {
47
- emitEvent(EVENT_IS_TRACKING, serializeIsTracking(HyperTrack.isTracking).toWritableMap())
58
+ emitEvent(
59
+ EVENT_IS_TRACKING,
60
+ serializeIsTracking(HyperTrack.isTracking).toWritableMap(),
61
+ )
48
62
  }
63
+
49
64
  EVENT_LOCATION -> {
50
- emitEvent(EVENT_LOCATION, serializeLocationResult(HyperTrack.location).toWritableMap())
65
+ emitEvent(
66
+ EVENT_LOCATION,
67
+ serializeLocationResult(HyperTrack.location).toWritableMap(),
68
+ )
51
69
  }
70
+
52
71
  else -> Unit
53
72
  }
54
73
  // Keep: Required for RN built in Event Emitter Calls.
@@ -111,6 +130,11 @@ class HyperTrackReactNativePlugin(reactContext: ReactApplicationContext?) :
111
130
  HyperTrackSdkWrapper.getName().toPromise(promise)
112
131
  }
113
132
 
133
+ @ReactMethod
134
+ fun getOrders(promise: Promise) {
135
+ HyperTrackSdkWrapper.getOrders().toPromise(promise)
136
+ }
137
+
114
138
  @ReactMethod
115
139
  fun getWorkerHandle(promise: Promise) {
116
140
  HyperTrackSdkWrapper.getWorkerHandle().toPromise(promise)
@@ -156,33 +180,43 @@ class HyperTrackReactNativePlugin(reactContext: ReactApplicationContext?) :
156
180
  HyperTrackSdkWrapper.setWorkerHandle(args.toHashMap())
157
181
  }
158
182
 
159
- private fun initListeners(): List<HyperTrack.Cancellable> {
160
- return mutableListOf<HyperTrack.Cancellable>().also { result ->
161
- HyperTrack.subscribeToErrors {
162
- emitEvent(EVENT_ERRORS, serializeErrors(it).toWriteableArray())
163
- }.also {
164
- result.add(it)
165
- }
166
-
167
- HyperTrack.subscribeToIsAvailable {
168
- emitEvent(EVENT_IS_AVAILABLE, serializeIsAvailable(it).toWritableMap())
169
- }.also {
170
- result.add(it)
171
- }
172
-
173
- HyperTrack.subscribeToIsTracking {
174
- emitEvent(EVENT_IS_TRACKING, serializeIsTracking(it).toWritableMap())
175
- }.also {
176
- result.add(it)
177
- }
178
-
179
- HyperTrack.subscribeToLocation {
180
- emitEvent(EVENT_LOCATION, serializeLocationResult(it).toWritableMap())
181
- }.also {
182
- result.add(it)
183
- }
183
+ private fun initListeners(): List<HyperTrack.Cancellable> =
184
+ mutableListOf<HyperTrack.Cancellable>().also { result ->
185
+ HyperTrack
186
+ .subscribeToErrors {
187
+ emitEvent(EVENT_ERRORS, serializeErrors(it).toWriteableArray())
188
+ }.also {
189
+ result.add(it)
190
+ }
191
+
192
+ HyperTrack
193
+ .subscribeToIsAvailable {
194
+ emitEvent(EVENT_IS_AVAILABLE, serializeIsAvailable(it).toWritableMap())
195
+ }.also {
196
+ result.add(it)
197
+ }
198
+
199
+ HyperTrack
200
+ .subscribeToIsTracking {
201
+ emitEvent(EVENT_IS_TRACKING, serializeIsTracking(it).toWritableMap())
202
+ }.also {
203
+ result.add(it)
204
+ }
205
+
206
+ HyperTrack
207
+ .subscribeToLocation {
208
+ emitEvent(EVENT_LOCATION, serializeLocationResult(it).toWritableMap())
209
+ }.also {
210
+ result.add(it)
211
+ }
212
+
213
+ HyperTrack
214
+ .subscribeToOrders {
215
+ emitEvent(EVENT_ORDERS, serializeOrders(it.values).toWritableMap())
216
+ }.also {
217
+ result.add(it)
218
+ }
184
219
  }
185
- }
186
220
 
187
221
  private fun emitEvent(
188
222
  event: String,
@@ -209,6 +243,7 @@ class HyperTrackReactNativePlugin(reactContext: ReactApplicationContext?) :
209
243
  private const val EVENT_IS_TRACKING = "isTracking"
210
244
  private const val EVENT_LOCATE = "locate"
211
245
  private const val EVENT_LOCATION = "location"
246
+ private const val EVENT_ORDERS = "orders"
212
247
 
213
248
  const val NAME = "HyperTrackReactNativePlugin"
214
249
  }
@@ -5,11 +5,8 @@ import com.facebook.react.bridge.ReactApplicationContext
5
5
  import com.facebook.react.uimanager.ViewManager
6
6
 
7
7
  class HyperTrackSdkPackage : ReactPackage {
8
- override fun createNativeModules(reactContext: ReactApplicationContext): MutableList<NativeModule> {
9
- return listOf(HyperTrackReactNativePlugin(reactContext)).toMutableList()
10
- }
8
+ override fun createNativeModules(reactContext: ReactApplicationContext): MutableList<NativeModule> =
9
+ listOf(HyperTrackReactNativePlugin(reactContext)).toMutableList()
11
10
 
12
- override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
13
- return emptyList()
14
- }
11
+ override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> = emptyList()
15
12
  }
@@ -60,8 +60,8 @@ internal fun <T> WrapperResult<T>.toPromise(promise: Promise) {
60
60
  }
61
61
 
62
62
  @Suppress("UNCHECKED_CAST")
63
- internal fun List<Any>.toWriteableArray(): WritableArray {
64
- return Arguments.createArray().also { writableArray ->
63
+ internal fun List<Any>.toWriteableArray(): WritableArray =
64
+ Arguments.createArray().also { writableArray ->
65
65
  forEach {
66
66
  when (it) {
67
67
  is String -> {
@@ -78,7 +78,6 @@ internal fun List<Any>.toWriteableArray(): WritableArray {
78
78
  }
79
79
  }
80
80
  }
81
- }
82
81
 
83
82
  @Suppress("UNCHECKED_CAST")
84
83
  internal fun Map<String, Any?>.toWritableMap(): WritableMap {
@@ -21,6 +21,7 @@ import com.reactnativehypertracksdk.common.Serialization.serializeLocationSucces
21
21
  import com.reactnativehypertracksdk.common.Serialization.serializeLocationWithDeviationSuccess
22
22
  import com.reactnativehypertracksdk.common.Serialization.serializeMetadata
23
23
  import com.reactnativehypertracksdk.common.Serialization.serializeName
24
+ import com.reactnativehypertracksdk.common.Serialization.serializeOrders
24
25
  import com.reactnativehypertracksdk.common.Serialization.serializeWorkerHandle
25
26
 
26
27
  typealias Serialized = Map<String, Any?>
@@ -30,8 +31,8 @@ typealias Serialized = Map<String, Any?>
30
31
  * It receives serialized params.
31
32
  */
32
33
  internal object HyperTrackSdkWrapper {
33
- fun addGeotag(args: Serialized): WrapperResult<Serialized> {
34
- return deserializeGeotagData(args)
34
+ fun addGeotag(args: Serialized): WrapperResult<Serialized> =
35
+ deserializeGeotagData(args)
35
36
  .flatMapSuccess { geotag ->
36
37
  // TODO: return proper error if JSON is wrong
37
38
  val geotagMetadata = Json.fromMap(geotag.data)!!
@@ -59,18 +60,17 @@ internal object HyperTrackSdkWrapper {
59
60
  )
60
61
  } else {
61
62
  HyperTrack.addGeotag(geotagMetadata, expectedLocation)
62
- }
63
- .let {
64
- when (it) {
65
- is Result.Failure -> {
66
- serializeLocationErrorFailure(it.failure)
67
- }
68
-
69
- is Result.Success -> {
70
- serializeLocationWithDeviationSuccess(it.success)
71
- }
63
+ }.let {
64
+ when (it) {
65
+ is Result.Failure -> {
66
+ serializeLocationErrorFailure(it.failure)
67
+ }
68
+
69
+ is Result.Success -> {
70
+ serializeLocationWithDeviationSuccess(it.success)
72
71
  }
73
72
  }
73
+ }
74
74
  } else {
75
75
  if (orderHandle != null || orderStatus != null) {
76
76
  if (orderHandle == null || orderStatus == null) {
@@ -83,110 +83,94 @@ internal object HyperTrackSdkWrapper {
83
83
  )
84
84
  } else {
85
85
  HyperTrack.addGeotag(geotagMetadata)
86
- }
87
- .let { serializeLocationResult(it) }
86
+ }.let { serializeLocationResult(it) }
88
87
  }.let {
89
88
  Success(it)
90
89
  }
91
90
  }
92
- }
93
91
 
94
- fun getDeviceId(): WrapperResult<Serialized> {
95
- return Success(serializeDeviceId(HyperTrack.deviceID))
96
- }
92
+ fun getDeviceId(): WrapperResult<Serialized> = Success(serializeDeviceId(HyperTrack.deviceID))
97
93
 
98
- fun getDynamicPublishableKey(): WrapperResult<Serialized> {
99
- return Success(serializeDynamicPublishableKey(HyperTrack.dynamicPublishableKey))
100
- }
94
+ fun getDynamicPublishableKey(): WrapperResult<Serialized> = Success(serializeDynamicPublishableKey(HyperTrack.dynamicPublishableKey))
101
95
 
102
- fun getErrors(): WrapperResult<List<Serialized>> {
103
- return Success(serializeErrors(HyperTrack.errors))
104
- }
96
+ fun getErrors(): WrapperResult<List<Serialized>> = Success(serializeErrors(HyperTrack.errors))
105
97
 
106
- fun getIsAvailable(): WrapperResult<Serialized> {
107
- return Success(
98
+ fun getIsAvailable(): WrapperResult<Serialized> =
99
+ Success(
108
100
  serializeIsAvailable(HyperTrack.isAvailable),
109
101
  )
110
- }
111
102
 
112
- fun getIsTracking(): WrapperResult<Serialized> {
113
- return Success(
103
+ fun getIsTracking(): WrapperResult<Serialized> =
104
+ Success(
114
105
  serializeIsTracking(HyperTrack.isTracking),
115
106
  )
116
- }
117
107
 
118
- fun getLocation(): WrapperResult<Serialized> {
119
- return HyperTrack
108
+ fun getLocation(): WrapperResult<Serialized> =
109
+ HyperTrack
120
110
  .location
121
111
  .let {
122
112
  when (it) {
123
113
  is Result.Failure -> serializeLocationErrorFailure(it.failure)
124
114
  is Result.Success -> serializeLocationSuccess(it.success)
125
115
  }
126
- }
127
- .let { Success(it) }
128
- }
116
+ }.let { Success(it) }
129
117
 
130
- fun getMetadata(): WrapperResult<Serialized> {
131
- return Success(
118
+ fun getMetadata(): WrapperResult<Serialized> =
119
+ Success(
132
120
  serializeMetadata(HyperTrack.metadata.toMap()),
133
121
  )
134
- }
135
122
 
136
- fun getName(): WrapperResult<Serialized> {
137
- return Success(
123
+ fun getName(): WrapperResult<Serialized> =
124
+ Success(
138
125
  serializeName(HyperTrack.name),
139
126
  )
140
- }
141
127
 
142
- fun getWorkerHandle(): WrapperResult<Serialized> {
143
- return Success(
128
+ fun getOrders(): WrapperResult<Serialized> =
129
+ Success(
130
+ serializeOrders(HyperTrack.orders.values),
131
+ )
132
+
133
+ fun getWorkerHandle(): WrapperResult<Serialized> =
134
+ Success(
144
135
  serializeWorkerHandle(HyperTrack.workerHandle),
145
136
  )
146
- }
147
137
 
148
- fun setDynamicPublishableKey(args: Serialized): WrapperResult<Unit> {
149
- return deserializeDynamicPublishableKey(args)
138
+ fun setDynamicPublishableKey(args: Serialized): WrapperResult<Unit> =
139
+ deserializeDynamicPublishableKey(args)
150
140
  .mapSuccess { publishableKey ->
151
141
  HyperTrack.dynamicPublishableKey = publishableKey
152
142
  }
153
- }
154
143
 
155
- fun setIsAvailable(args: Serialized): WrapperResult<Unit> {
156
- return deserializeIsAvailable(args)
144
+ fun setIsAvailable(args: Serialized): WrapperResult<Unit> =
145
+ deserializeIsAvailable(args)
157
146
  .mapSuccess { isAvailable ->
158
147
  HyperTrack.isAvailable = isAvailable
159
148
  }
160
- }
161
149
 
162
- fun setIsTracking(args: Serialized): WrapperResult<Unit> {
163
- return deserializeIsTracking(args)
150
+ fun setIsTracking(args: Serialized): WrapperResult<Unit> =
151
+ deserializeIsTracking(args)
164
152
  .mapSuccess { isTracking ->
165
153
  HyperTrack.isTracking = isTracking
166
154
  }
167
- }
168
155
 
169
- fun setMetadata(args: Serialized): WrapperResult<Unit> {
170
- return deserializeMetadata(args)
156
+ fun setMetadata(args: Serialized): WrapperResult<Unit> =
157
+ deserializeMetadata(args)
171
158
  .flatMapSuccess { metadata ->
172
159
  WrapperResult.tryAsResult {
173
160
  // TODO: return proper error if JSON is wrong
174
161
  HyperTrack.metadata = Json.fromMap(metadata)!!
175
162
  }
176
163
  }
177
- }
178
164
 
179
- fun setName(args: Serialized): WrapperResult<Unit> {
180
- return deserializeName(args)
165
+ fun setName(args: Serialized): WrapperResult<Unit> =
166
+ deserializeName(args)
181
167
  .mapSuccess { name ->
182
168
  HyperTrack.name = name
183
169
  }
184
- }
185
170
 
186
- fun setWorkerHandle(args: Serialized): WrapperResult<Unit> {
187
- return deserializeWorkerHandle(args)
171
+ fun setWorkerHandle(args: Serialized): WrapperResult<Unit> =
172
+ deserializeWorkerHandle(args)
188
173
  .mapSuccess { workerHandle ->
189
174
  HyperTrack.workerHandle = workerHandle
190
175
  }
191
- }
192
176
  }
@@ -16,6 +16,7 @@ internal enum class SdkMethod {
16
16
  getLocation,
17
17
  getMetadata,
18
18
  getName,
19
+ getOrders,
19
20
  getWorkerHandle,
20
21
  locate,
21
22
  setDynamicPublishableKey,