hypertrack-sdk-react-native 9.1.1 → 9.2.0

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 (95) hide show
  1. package/CHANGELOG.md +148 -3
  2. package/README.md +3 -3
  3. package/android/.gradle/7.2/dependencies-accessors/dependencies-accessors.lock +0 -0
  4. package/android/.gradle/7.2/dependencies-accessors/gc.properties +0 -0
  5. package/android/.gradle/7.2/executionHistory/executionHistory.lock +0 -0
  6. package/android/.gradle/7.2/fileChanges/last-build.bin +0 -0
  7. package/android/.gradle/7.2/fileHashes/fileHashes.bin +0 -0
  8. package/android/.gradle/7.2/fileHashes/fileHashes.lock +0 -0
  9. package/android/.gradle/7.2/gc.properties +0 -0
  10. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  11. package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
  12. package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
  13. package/android/.gradle/checksums/checksums.lock +0 -0
  14. package/android/.gradle/checksums/md5-checksums.bin +0 -0
  15. package/android/.gradle/checksums/sha1-checksums.bin +0 -0
  16. package/android/.gradle/vcs-1/gc.properties +0 -0
  17. package/android/.idea/compiler.xml +6 -0
  18. package/android/.idea/gradle.xml +19 -0
  19. package/android/.idea/jarRepositories.xml +35 -0
  20. package/android/.idea/kotlinc.xml +6 -0
  21. package/android/.idea/misc.xml +9 -0
  22. package/android/.idea/vcs.xml +6 -0
  23. package/android/local.properties +8 -0
  24. package/android/src/main/java/com/reactnativehypertracksdk/HyperTrackReactNativePlugin.kt +4 -4
  25. package/android/src/main/java/com/reactnativehypertracksdk/ReactNativeSerialization.kt +16 -17
  26. package/android/src/main/java/com/reactnativehypertracksdk/common/GeotagData.kt +13 -0
  27. package/android/src/main/java/com/reactnativehypertracksdk/common/HyperTrackSdkWrapper.kt +45 -19
  28. package/android/src/main/java/com/reactnativehypertracksdk/common/Serialization.kt +115 -40
  29. package/hypertrack-sdk-react-native.podspec +1 -1
  30. package/ios/common/GeotagData.swift +11 -0
  31. package/ios/common/HyperTrackSDKWrapper.swift +9 -4
  32. package/ios/common/Serialization.swift +140 -61
  33. package/lib/commonjs/HyperTrack/HyperTrack.js +90 -22
  34. package/lib/commonjs/HyperTrack/HyperTrack.js.map +1 -1
  35. package/lib/commonjs/HyperTrack/data_types/HyperTrackError.js +4 -4
  36. package/lib/commonjs/HyperTrack/data_types/HyperTrackError.js.map +1 -1
  37. package/lib/commonjs/HyperTrack/data_types/Location.js.map +1 -1
  38. package/lib/commonjs/HyperTrack/data_types/LocationWithDeviation.js +6 -0
  39. package/lib/commonjs/HyperTrack/data_types/LocationWithDeviation.js.map +1 -0
  40. package/lib/commonjs/HyperTrack/data_types/Result.js +2 -0
  41. package/lib/commonjs/HyperTrack/data_types/Result.js.map +1 -0
  42. package/lib/commonjs/HyperTrack/data_types/internal/{LocationResponse.js → GeotagData.js} +1 -1
  43. package/lib/commonjs/HyperTrack/data_types/internal/GeotagData.js.map +1 -0
  44. package/lib/commonjs/HyperTrack/data_types/internal/LocationInternal.js +2 -0
  45. package/lib/commonjs/HyperTrack/data_types/internal/LocationInternal.js.map +1 -0
  46. package/lib/commonjs/HyperTrack/data_types/internal/LocationWithDeviationInternal.js +6 -0
  47. package/lib/commonjs/HyperTrack/data_types/internal/LocationWithDeviationInternal.js.map +1 -0
  48. package/lib/commonjs/index.js +19 -0
  49. package/lib/commonjs/index.js.map +1 -1
  50. package/lib/module/HyperTrack/HyperTrack.js +90 -22
  51. package/lib/module/HyperTrack/HyperTrack.js.map +1 -1
  52. package/lib/module/HyperTrack/data_types/HyperTrackError.js +3 -3
  53. package/lib/module/HyperTrack/data_types/HyperTrackError.js.map +1 -1
  54. package/lib/module/HyperTrack/data_types/Location.js.map +1 -1
  55. package/lib/module/HyperTrack/data_types/LocationWithDeviation.js +2 -0
  56. package/lib/module/HyperTrack/data_types/LocationWithDeviation.js.map +1 -0
  57. package/lib/module/HyperTrack/data_types/Result.js +2 -0
  58. package/lib/module/HyperTrack/data_types/Result.js.map +1 -0
  59. package/lib/module/HyperTrack/data_types/internal/GeotagData.js +2 -0
  60. package/lib/module/HyperTrack/data_types/internal/GeotagData.js.map +1 -0
  61. package/lib/module/HyperTrack/data_types/internal/LocationInternal.js +2 -0
  62. package/lib/module/HyperTrack/data_types/internal/LocationInternal.js.map +1 -0
  63. package/lib/module/HyperTrack/data_types/internal/LocationWithDeviationInternal.js +2 -0
  64. package/lib/module/HyperTrack/data_types/internal/LocationWithDeviationInternal.js.map +1 -0
  65. package/lib/module/index.js +1 -0
  66. package/lib/module/index.js.map +1 -1
  67. package/lib/typescript/HyperTrack/HyperTrack.d.ts +17 -1
  68. package/lib/typescript/HyperTrack/data_types/Location.d.ts +2 -5
  69. package/lib/typescript/HyperTrack/data_types/LocationWithDeviation.d.ts +5 -0
  70. package/lib/typescript/HyperTrack/data_types/Result.d.ts +9 -0
  71. package/lib/typescript/HyperTrack/data_types/internal/GeotagData.d.ts +5 -0
  72. package/lib/typescript/HyperTrack/data_types/internal/LocationInternal.d.ts +7 -0
  73. package/lib/typescript/HyperTrack/data_types/internal/LocationWithDeviationInternal.d.ts +8 -0
  74. package/lib/typescript/index.d.ts +2 -1
  75. package/package.json +1 -1
  76. package/src/HyperTrack/HyperTrack.ts +160 -46
  77. package/src/HyperTrack/data_types/Location.ts +2 -5
  78. package/src/HyperTrack/data_types/LocationWithDeviation.ts +6 -0
  79. package/src/HyperTrack/data_types/Result.ts +11 -0
  80. package/src/HyperTrack/data_types/internal/GeotagData.ts +6 -0
  81. package/src/HyperTrack/data_types/internal/LocationInternal.ts +7 -0
  82. package/src/HyperTrack/data_types/internal/LocationWithDeviationInternal.ts +9 -0
  83. package/src/index.tsx +6 -2
  84. package/android/src/main/java/com/reactnativehypertracksdk/common/Geotag.kt +0 -9
  85. package/lib/commonjs/HyperTrack/data_types/internal/Geotag.js +0 -2
  86. package/lib/commonjs/HyperTrack/data_types/internal/Geotag.js.map +0 -1
  87. package/lib/commonjs/HyperTrack/data_types/internal/LocationResponse.js.map +0 -1
  88. package/lib/module/HyperTrack/data_types/internal/Geotag.js +0 -2
  89. package/lib/module/HyperTrack/data_types/internal/Geotag.js.map +0 -1
  90. package/lib/module/HyperTrack/data_types/internal/LocationResponse.js +0 -2
  91. package/lib/module/HyperTrack/data_types/internal/LocationResponse.js.map +0 -1
  92. package/lib/typescript/HyperTrack/data_types/internal/Geotag.d.ts +0 -3
  93. package/lib/typescript/HyperTrack/data_types/internal/LocationResponse.d.ts +0 -11
  94. package/src/HyperTrack/data_types/internal/Geotag.ts +0 -3
  95. package/src/HyperTrack/data_types/internal/LocationResponse.ts +0 -14
@@ -0,0 +1,13 @@
1
+ package com.reactnativehypertracksdk.common
2
+
3
+ import android.location.Location
4
+
5
+ /**
6
+ * The data that represents geotag to create
7
+ *
8
+ * @param data Geotag payload
9
+ */
10
+ internal data class GeotagData(
11
+ val data: Map<String, Any?>,
12
+ val expectedLocation: Location?
13
+ )
@@ -1,15 +1,17 @@
1
1
  package com.reactnativehypertracksdk.common
2
2
 
3
3
  import com.hypertrack.sdk.*
4
+ import com.hypertrack.sdk.GeotagResult
4
5
  import com.reactnativehypertracksdk.common.Serialization.deserializeAvailability
5
6
  import com.reactnativehypertracksdk.common.Serialization.deserializeDeviceName
6
7
  import com.reactnativehypertracksdk.common.Serialization.deserializeGeotagData
7
8
  import com.reactnativehypertracksdk.common.Serialization.serializeDeviceId
8
9
  import com.reactnativehypertracksdk.common.Serialization.serializeErrors
9
- import com.reactnativehypertracksdk.common.Serialization.serializeFailure
10
10
  import com.reactnativehypertracksdk.common.Serialization.serializeIsAvailable
11
11
  import com.reactnativehypertracksdk.common.Serialization.serializeIsTracking
12
- import com.reactnativehypertracksdk.common.Serialization.serializeSuccess
12
+ import com.reactnativehypertracksdk.common.Serialization.serializeLocationErrorFailure
13
+ import com.reactnativehypertracksdk.common.Serialization.serializeLocationSuccess
14
+ import com.reactnativehypertracksdk.common.Serialization.serializeLocationWithDeviationSuccess
13
15
  import java.lang.IllegalStateException
14
16
  import java.lang.RuntimeException
15
17
 
@@ -30,8 +32,7 @@ internal object HyperTrackSdkWrapper {
30
32
  args: Map<String, Any?>
31
33
  ): Result<HyperTrack> {
32
34
  return try {
33
- SdkInitParams
34
- .fromMap(args)
35
+ SdkInitParams.fromMap(args)
35
36
  .flatMapSuccess { initParams ->
36
37
  _sdkInstance = HyperTrack.getInstance(initParams.publishableKey)
37
38
  if (initParams.loggingEnabled) {
@@ -40,7 +41,7 @@ internal object HyperTrackSdkWrapper {
40
41
  if (initParams.allowMockLocations) {
41
42
  sdkInstance.allowMockLocations()
42
43
  }
43
- this.sdkInstance.backgroundTrackingRequirement(
44
+ sdkInstance.backgroundTrackingRequirement(
44
45
  initParams.requireBackgroundTrackingPermission
45
46
  )
46
47
  Success(sdkInstance)
@@ -73,20 +74,45 @@ internal object HyperTrackSdkWrapper {
73
74
  return deserializeGeotagData(args)
74
75
  .flatMapSuccess { geotag ->
75
76
  sdkInstance
76
- .addGeotag(geotag.data)
77
+ .addGeotag(geotag.data, geotag.expectedLocation)
77
78
  .let { result ->
78
- when (result) {
79
- is GeotagResult.SuccessWithDeviation -> {
80
- serializeSuccess(result.deviceLocation)
81
- }
82
- is GeotagResult.Success -> {
83
- serializeSuccess(result.deviceLocation)
84
- }
85
- is GeotagResult.Error -> {
86
- serializeFailure(getLocationError(result.reason))
79
+ if(geotag.expectedLocation == null) {
80
+ when (result) {
81
+ is GeotagResult.SuccessWithDeviation -> {
82
+ // not supposed to happen
83
+ serializeLocationSuccess(result.deviceLocation)
84
+ }
85
+
86
+ is GeotagResult.Success -> {
87
+ serializeLocationSuccess(result.deviceLocation)
88
+ }
89
+
90
+ is GeotagResult.Error -> {
91
+ serializeLocationErrorFailure(getLocationError(result.reason))
92
+ }
93
+
94
+ else -> {
95
+ throw IllegalArgumentException()
96
+ }
87
97
  }
88
- else -> {
89
- throw IllegalArgumentException()
98
+ } else {
99
+ when (result) {
100
+ is GeotagResult.SuccessWithDeviation -> {
101
+ serializeLocationWithDeviationSuccess(result.deviceLocation, result.deviationDistance.toDouble())
102
+ }
103
+
104
+ is GeotagResult.Success -> {
105
+ // not supposed to happen
106
+ serializeLocationWithDeviationSuccess(result.deviceLocation, 0.0)
107
+ }
108
+
109
+ is GeotagResult.Error -> {
110
+ serializeLocationErrorFailure(getLocationError(result.reason))
111
+ }
112
+
113
+ else -> {
114
+ throw IllegalArgumentException()
115
+ }
90
116
  }
91
117
  }
92
118
  }
@@ -135,9 +161,9 @@ internal object HyperTrackSdkWrapper {
135
161
  return sdkInstance.latestLocation
136
162
  .let { result ->
137
163
  if (result.isSuccess) {
138
- serializeSuccess(result.value)
164
+ serializeLocationSuccess(result.value)
139
165
  } else {
140
- serializeFailure(getLocationError(result.error))
166
+ serializeLocationErrorFailure(getLocationError(result.error))
141
167
  }
142
168
  }
143
169
  .let { Success(it) }
@@ -14,18 +14,22 @@ internal object Serialization {
14
14
  }
15
15
  }
16
16
 
17
- fun serializeSuccess(location: Location): Map<String, Any?> {
18
- return mapOf(
19
- KEY_TYPE to TYPE_RESULT_SUCCESS,
20
- KEY_VALUE to serializeLocation(location)
21
- )
17
+ fun serializeLocationSuccess(location: Location): Map<String, Any?> {
18
+ return serializeSuccess(serializeLocation(location))
22
19
  }
23
20
 
24
- fun serializeFailure(locationError: LocationError): Map<String, Any?> {
25
- return mapOf(
26
- KEY_TYPE to TYPE_RESULT_FAILURE,
27
- KEY_VALUE to serializeLocationError(locationError)
28
- )
21
+ fun serializeLocationWithDeviationSuccess(
22
+ location: Location,
23
+ deviation: Double
24
+ ): Map<String, Any?> {
25
+ return serializeSuccess(serializeLocationWithDeviation(
26
+ location,
27
+ deviation
28
+ ))
29
+ }
30
+
31
+ fun serializeLocationErrorFailure(locationError: LocationError): Map<String, Any?> {
32
+ return serializeFailure(serializeLocationError(locationError))
29
33
  }
30
34
 
31
35
  fun serializeIsTracking(isTracking: Boolean): Map<String, Any?> {
@@ -42,34 +46,6 @@ internal object Serialization {
42
46
  )
43
47
  }
44
48
 
45
- fun serializeLocation(location: Location): Map<String, Any?> {
46
- return mapOf(
47
- KEY_TYPE to TYPE_LOCATION,
48
- KEY_VALUE to mapOf(
49
- KEY_LATITUDE to location.latitude,
50
- KEY_LONGITUDE to location.longitude
51
- )
52
- )
53
- }
54
-
55
- fun serializeLocationError(locationError: LocationError): Map<String, Any?> {
56
- return when (locationError) {
57
- NotRunning -> {
58
- mapOf(KEY_TYPE to TYPE_LOCATION_ERROR_NOT_RUNNING)
59
- }
60
- Starting -> {
61
- mapOf(KEY_TYPE to TYPE_LOCATION_ERROR_STARTING)
62
- }
63
- is Errors -> {
64
- mapOf(
65
- KEY_TYPE to TYPE_LOCATION_ERROR_ERRORS,
66
- KEY_VALUE to locationError.errors
67
- .map { serializeHypertrackError(it) }
68
- )
69
- }
70
- }
71
- }
72
-
73
49
  fun serializeHypertrackError(error: HyperTrackError): Map<String, String> {
74
50
  return mapOf(
75
51
  KEY_TYPE to TYPE_HYPERTRACK_ERROR,
@@ -102,12 +78,16 @@ internal object Serialization {
102
78
  }
103
79
  }
104
80
 
105
- fun deserializeGeotagData(map: Map<String, Any?>): Result<Geotag> {
81
+ fun deserializeGeotagData(map: Map<String, Any?>): Result<GeotagData> {
106
82
  return parse(map) {
107
83
  val data = it
108
84
  .get<Map<String, Any?>>(KEY_GEOTAG_DATA)
109
85
  .getOrThrow()
110
- Geotag(data)
86
+ val locationData = it
87
+ .getOptional<Map<String, Any?>>(KEY_GEOTAG_EXPECTED_LOCATION)
88
+ .getOrThrow()
89
+ val location = locationData?.let { deserializeLocation(it).getOrThrow() }
90
+ GeotagData(data, location)
111
91
  }
112
92
  }
113
93
 
@@ -154,6 +134,21 @@ internal object Serialization {
154
134
  }
155
135
  }
156
136
 
137
+ inline fun <reified T> getOptional(
138
+ key: String
139
+ ): Result<T?> {
140
+ return try {
141
+ Success(source[key] as T?)
142
+ } catch (e: Exception) {
143
+ Failure(
144
+ ParsingException(key, e)
145
+ .also {
146
+ _exceptions.add(it)
147
+ }
148
+ )
149
+ }
150
+ }
151
+
157
152
  inline fun <reified T> assertValue(
158
153
  key: String,
159
154
  value: Any
@@ -179,6 +174,82 @@ internal object Serialization {
179
174
  exception: Exception
180
175
  ) : Exception("Invalid value for '$key': $exception", exception)
181
176
 
177
+ private fun deserializeLocation(map: Map<String, Any?>): Result<Location> {
178
+ return parse(map) {
179
+ it.assertValue<String>(key = KEY_TYPE, value = TYPE_LOCATION)
180
+ val value = it
181
+ .get<Map<String, Any?>>(KEY_VALUE)
182
+ .getOrThrow()
183
+ parse(value) { parser ->
184
+ val latitude = parser
185
+ .get<Double>(KEY_LATITUDE)
186
+ .getOrThrow()
187
+ val longitude = parser
188
+ .get<Double>(KEY_LONGITUDE)
189
+ .getOrThrow()
190
+ Location("api").also {
191
+ it.latitude = latitude
192
+ it.longitude = longitude
193
+ }
194
+ }.getOrThrow()
195
+ }
196
+ }
197
+
198
+ private fun serializeLocationWithDeviation(
199
+ location: Location,
200
+ deviation: Double
201
+ ): Map<String, Any?> {
202
+ return mapOf(
203
+ KEY_TYPE to TYPE_LOCATION,
204
+ KEY_VALUE to mapOf(
205
+ KEY_LOCATION to serializeLocation(location),
206
+ KEY_DEVIATION to deviation
207
+ )
208
+ )
209
+ }
210
+
211
+ private fun serializeFailure(failure: Map<String, Any?>): Map<String, Any?> {
212
+ return mapOf(
213
+ KEY_TYPE to TYPE_RESULT_FAILURE,
214
+ KEY_VALUE to failure
215
+ )
216
+ }
217
+
218
+ private fun serializeSuccess(success: Map<String, Any?>): Map<String, Any?> {
219
+ return mapOf(
220
+ KEY_TYPE to TYPE_RESULT_SUCCESS,
221
+ KEY_VALUE to success
222
+ )
223
+ }
224
+
225
+ private fun serializeLocation(location: Location): Map<String, Any?> {
226
+ return mapOf(
227
+ KEY_TYPE to TYPE_LOCATION,
228
+ KEY_VALUE to mapOf(
229
+ KEY_LATITUDE to location.latitude,
230
+ KEY_LONGITUDE to location.longitude
231
+ )
232
+ )
233
+ }
234
+
235
+ private fun serializeLocationError(locationError: LocationError): Map<String, Any?> {
236
+ return when (locationError) {
237
+ NotRunning -> {
238
+ mapOf(KEY_TYPE to TYPE_LOCATION_ERROR_NOT_RUNNING)
239
+ }
240
+ Starting -> {
241
+ mapOf(KEY_TYPE to TYPE_LOCATION_ERROR_STARTING)
242
+ }
243
+ is Errors -> {
244
+ mapOf(
245
+ KEY_TYPE to TYPE_LOCATION_ERROR_ERRORS,
246
+ KEY_VALUE to locationError.errors
247
+ .map { serializeHypertrackError(it) }
248
+ )
249
+ }
250
+ }
251
+ }
252
+
182
253
  private const val KEY_TYPE = "type"
183
254
  private const val KEY_VALUE = "value"
184
255
 
@@ -186,6 +257,7 @@ internal object Serialization {
186
257
  private const val TYPE_RESULT_FAILURE = "failure"
187
258
 
188
259
  private const val TYPE_LOCATION = "location"
260
+ private const val TYPE_LOCATION_WITH_DEVIATION = "locationWithDeviation"
189
261
  private const val TYPE_AVAILABILITY = "isAvailable"
190
262
  private const val TYPE_DEVICE_NAME = "deviceName"
191
263
  private const val TYPE_DEVICE_ID = "deviceID"
@@ -200,4 +272,7 @@ internal object Serialization {
200
272
  private const val KEY_LONGITUDE = "longitude"
201
273
 
202
274
  const val KEY_GEOTAG_DATA = "data"
275
+ const val KEY_GEOTAG_EXPECTED_LOCATION = "expectedLocation"
276
+ const val KEY_DEVIATION = "deviation"
277
+ const val KEY_LOCATION = "location"
203
278
  }
@@ -18,7 +18,7 @@ Pod::Spec.new do |s|
18
18
  s.source_files = "ios/**/*.{h,m,mm,swift}"
19
19
 
20
20
  s.dependency "React-Core"
21
- s.dependency 'HyperTrack/Objective-C', '4.14.0'
21
+ s.dependency 'HyperTrack/Objective-C', '4.15.0'
22
22
 
23
23
  # Don't install the dependencies when we run `pod install` in the old architecture.
24
24
  if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
@@ -0,0 +1,11 @@
1
+ import HyperTrack
2
+
3
+ struct GeotagData {
4
+ let data: [String: Any]
5
+ let expectedLocation: HyperTrack.Location?
6
+
7
+ init(data: [String: Any], expectedLocation: HyperTrack.Location?) {
8
+ self.data = data
9
+ self.expectedLocation = expectedLocation
10
+ }
11
+ }
@@ -88,10 +88,15 @@ func isAvailable() -> Result<SuccessResult, FailureResult> {
88
88
  }
89
89
 
90
90
  func addGeotag(_ args: Dictionary<String, Any>) -> Result<SuccessResult, FailureResult> {
91
- return deserializeGeotagData(args).flatMap { data in
92
- let metadata: HyperTrack.JSON.Object = getJSON(data)
93
- let result = sdkInstance.addGeotag(metadata)
94
- return .success(.dict(serializeLocationResult(result)))
91
+ return deserializeGeotagData(args).flatMap { geotagData in
92
+ let metadata: HyperTrack.JSON.Object = getJSON(geotagData.data)
93
+ if let expectedLocation = geotagData.expectedLocation {
94
+ let result = sdkInstance.addGeotag(metadata, expectedLocation: expectedLocation)
95
+ return .success(.dict(serializeExpectedLocationResult(result)))
96
+ } else {
97
+ let result = sdkInstance.addGeotag(metadata)
98
+ return .success(.dict(serializeLocationResult(result)))
99
+ }
95
100
  }
96
101
  }
97
102