Skip to content

Commit cec4d91

Browse files
Fix deserialization (#112)
1 parent f0bd800 commit cec4d91

File tree

30 files changed

+215
-258
lines changed

30 files changed

+215
-258
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
55

66
## [Unreleased]
77

8+
## [13.5.1] - 2024-09-02
9+
10+
### Fixed
11+
12+
- Serialization issue with `Order.isInsideGeofence`
13+
814
## [13.5.0] - 2024-08-21
915

1016
### Added
@@ -908,3 +914,4 @@ Initial release.
908914
[13.3.5]: https://github.com/hypertrack/sdk-react-native/releases/tag/13.3.5
909915
[13.4.0]: https://github.com/hypertrack/sdk-react-native/releases/tag/13.4.0
910916
[13.5.0]: https://github.com/hypertrack/sdk-react-native/releases/tag/13.5.0
917+
[13.5.1]: https://github.com/hypertrack/sdk-react-native/releases/tag/13.5.1

docs/classes/HyperTrack.html

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

docs/enums/HyperTrackError.html

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

docs/index.html

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

docs/modules.html

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

docs/types/Errors.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/types/Failure.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/types/Location.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/types/LocationError.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/types/LocationWithDeviation.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/types/NotRunning.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/types/Order.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/types/OrderStatus.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/types/Result.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/types/Starting.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/types/Success.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

justfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ SEMVER_REGEX := "(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d
2929
_ask-confirm:
3030
@bash -c 'read confirmation; if [[ $confirmation != "y" && $confirmation != "Y" ]]; then echo "Okay 😮‍💨 😅"; exit 1; fi'
3131

32-
build: get-dependencies docs
32+
build: get-dependencies docs format
3333
yarn --cwd sdk prepare
3434
yarn --cwd plugin_android_location_services_google prepare
3535
yarn --cwd plugin_android_location_services_google_19_0_1 prepare
@@ -62,6 +62,7 @@ _latest-ios:
6262
@curl -s https://cocoapods.org/pods/HyperTrack | grep -m 1 -o -E "HyperTrack <span>{{SEMVER_REGEX}}" | grep -o -E '{{SEMVER_REGEX}}' | head -n 1
6363

6464
format:
65+
brew upgrade ktlint
6566
ktlint --format sdk/android/src/main/java/
6667

6768
open-docs: docs

plugin_android_location_services_google/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hypertrack-sdk-react-native-plugin-android-location-services-google",
3-
"version": "13.5.0",
3+
"version": "13.5.1",
44
"description": "A wrapper around `Location Services Google` plugin for HyperTrack SDK Android that is used with `hypertrack-sdk-react-native`",
55
"main": "lib/commonjs/index",
66
"module": "lib/module/index",
@@ -81,7 +81,6 @@
8181
"react": "*",
8282
"react-native": "*"
8383
},
84-
"packageManager": "yarn@3.6.1",
8584
"engines": {
8685
"node": ">= 18.0.0"
8786
},

plugin_android_location_services_google_19_0_1/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hypertrack-sdk-react-native-plugin-android-location-services-google-19-0-1",
3-
"version": "13.5.0",
3+
"version": "13.5.1",
44
"description": "A wrapper around `Location Services Google 19.0.1` plugin for HyperTrack SDK Android that is used with `hypertrack-sdk-react-native`",
55
"main": "lib/commonjs/index",
66
"module": "lib/module/index",
@@ -81,7 +81,6 @@
8181
"react": "*",
8282
"react-native": "*"
8383
},
84-
"packageManager": "yarn@3.6.1",
8584
"engines": {
8685
"node": ">= 18.0.0"
8786
},

plugin_android_push_service_firebase/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hypertrack-sdk-react-native-plugin-android-push-service-firebase",
3-
"version": "13.5.0",
3+
"version": "13.5.1",
44
"description": "A wrapper around `Push Service Firebase` plugin for HyperTrack SDK Android that is used with `hypertrack-sdk-react-native`",
55
"main": "lib/commonjs/index",
66
"module": "lib/module/index",
@@ -81,7 +81,6 @@
8181
"react": "*",
8282
"react-native": "*"
8383
},
84-
"packageManager": "yarn@3.6.1",
8584
"engines": {
8685
"node": ">= 18.0.0"
8786
},

sdk/android/src/main/java/com/reactnativehypertracksdk/HyperTrackReactNativePlugin.kt

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@ import com.reactnativehypertracksdk.common.Serialization.serializeOrders
2020
import com.reactnativehypertracksdk.common.Success
2121

2222
@ReactModule(name = HyperTrackReactNativePlugin.NAME)
23-
class HyperTrackReactNativePlugin(reactContext: ReactApplicationContext?) :
24-
ReactContextBaseJavaModule(reactContext) {
23+
class HyperTrackReactNativePlugin(
24+
reactContext: ReactApplicationContext?,
25+
) : ReactContextBaseJavaModule(reactContext) {
2526
private var locateSubscription: HyperTrack.Cancellable? = null
2627
private var subscriptions: List<HyperTrack.Cancellable>? = null
2728

28-
override fun getName(): String {
29-
return NAME
30-
}
29+
override fun getName(): String = NAME
3130

3231
/**
3332
* ReactNative built-in methods
@@ -181,39 +180,43 @@ class HyperTrackReactNativePlugin(reactContext: ReactApplicationContext?) :
181180
HyperTrackSdkWrapper.setWorkerHandle(args.toHashMap())
182181
}
183182

184-
private fun initListeners(): List<HyperTrack.Cancellable> {
185-
return mutableListOf<HyperTrack.Cancellable>().also { result ->
186-
HyperTrack.subscribeToErrors {
187-
emitEvent(EVENT_ERRORS, serializeErrors(it).toWriteableArray())
188-
}.also {
189-
result.add(it)
190-
}
191-
192-
HyperTrack.subscribeToIsAvailable {
193-
emitEvent(EVENT_IS_AVAILABLE, serializeIsAvailable(it).toWritableMap())
194-
}.also {
195-
result.add(it)
196-
}
197-
198-
HyperTrack.subscribeToIsTracking {
199-
emitEvent(EVENT_IS_TRACKING, serializeIsTracking(it).toWritableMap())
200-
}.also {
201-
result.add(it)
202-
}
203-
204-
HyperTrack.subscribeToLocation {
205-
emitEvent(EVENT_LOCATION, serializeLocationResult(it).toWritableMap())
206-
}.also {
207-
result.add(it)
208-
}
209-
210-
HyperTrack.subscribeToOrders {
211-
emitEvent(EVENT_ORDERS, serializeOrders(it.values).toWritableMap())
212-
}.also {
213-
result.add(it)
214-
}
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+
}
215219
}
216-
}
217220

218221
private fun emitEvent(
219222
event: String,

sdk/android/src/main/java/com/reactnativehypertracksdk/HyperTrackSdkPackage.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@ import com.facebook.react.bridge.ReactApplicationContext
55
import com.facebook.react.uimanager.ViewManager
66

77
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()
1110

12-
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
13-
return emptyList()
14-
}
11+
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> = emptyList()
1512
}

sdk/android/src/main/java/com/reactnativehypertracksdk/ReactNativeSerialization.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ internal fun <T> WrapperResult<T>.toPromise(promise: Promise) {
6060
}
6161

6262
@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 ->
6565
forEach {
6666
when (it) {
6767
is String -> {
@@ -78,7 +78,6 @@ internal fun List<Any>.toWriteableArray(): WritableArray {
7878
}
7979
}
8080
}
81-
}
8281

8382
@Suppress("UNCHECKED_CAST")
8483
internal fun Map<String, Any?>.toWritableMap(): WritableMap {

sdk/android/src/main/java/com/reactnativehypertracksdk/common/HyperTrackSdkWrapper.kt

Lines changed: 42 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ typealias Serialized = Map<String, Any?>
3131
* It receives serialized params.
3232
*/
3333
internal object HyperTrackSdkWrapper {
34-
fun addGeotag(args: Serialized): WrapperResult<Serialized> {
35-
return deserializeGeotagData(args)
34+
fun addGeotag(args: Serialized): WrapperResult<Serialized> =
35+
deserializeGeotagData(args)
3636
.flatMapSuccess { geotag ->
3737
// TODO: return proper error if JSON is wrong
3838
val geotagMetadata = Json.fromMap(geotag.data)!!
@@ -60,18 +60,17 @@ internal object HyperTrackSdkWrapper {
6060
)
6161
} else {
6262
HyperTrack.addGeotag(geotagMetadata, expectedLocation)
63-
}
64-
.let {
65-
when (it) {
66-
is Result.Failure -> {
67-
serializeLocationErrorFailure(it.failure)
68-
}
69-
70-
is Result.Success -> {
71-
serializeLocationWithDeviationSuccess(it.success)
72-
}
63+
}.let {
64+
when (it) {
65+
is Result.Failure -> {
66+
serializeLocationErrorFailure(it.failure)
67+
}
68+
69+
is Result.Success -> {
70+
serializeLocationWithDeviationSuccess(it.success)
7371
}
7472
}
73+
}
7574
} else {
7675
if (orderHandle != null || orderStatus != null) {
7776
if (orderHandle == null || orderStatus == null) {
@@ -84,116 +83,94 @@ internal object HyperTrackSdkWrapper {
8483
)
8584
} else {
8685
HyperTrack.addGeotag(geotagMetadata)
87-
}
88-
.let { serializeLocationResult(it) }
86+
}.let { serializeLocationResult(it) }
8987
}.let {
9088
Success(it)
9189
}
9290
}
93-
}
9491

95-
fun getDeviceId(): WrapperResult<Serialized> {
96-
return Success(serializeDeviceId(HyperTrack.deviceID))
97-
}
92+
fun getDeviceId(): WrapperResult<Serialized> = Success(serializeDeviceId(HyperTrack.deviceID))
9893

99-
fun getDynamicPublishableKey(): WrapperResult<Serialized> {
100-
return Success(serializeDynamicPublishableKey(HyperTrack.dynamicPublishableKey))
101-
}
94+
fun getDynamicPublishableKey(): WrapperResult<Serialized> = Success(serializeDynamicPublishableKey(HyperTrack.dynamicPublishableKey))
10295

103-
fun getErrors(): WrapperResult<List<Serialized>> {
104-
return Success(serializeErrors(HyperTrack.errors))
105-
}
96+
fun getErrors(): WrapperResult<List<Serialized>> = Success(serializeErrors(HyperTrack.errors))
10697

107-
fun getIsAvailable(): WrapperResult<Serialized> {
108-
return Success(
98+
fun getIsAvailable(): WrapperResult<Serialized> =
99+
Success(
109100
serializeIsAvailable(HyperTrack.isAvailable),
110101
)
111-
}
112102

113-
fun getIsTracking(): WrapperResult<Serialized> {
114-
return Success(
103+
fun getIsTracking(): WrapperResult<Serialized> =
104+
Success(
115105
serializeIsTracking(HyperTrack.isTracking),
116106
)
117-
}
118107

119-
fun getLocation(): WrapperResult<Serialized> {
120-
return HyperTrack
108+
fun getLocation(): WrapperResult<Serialized> =
109+
HyperTrack
121110
.location
122111
.let {
123112
when (it) {
124113
is Result.Failure -> serializeLocationErrorFailure(it.failure)
125114
is Result.Success -> serializeLocationSuccess(it.success)
126115
}
127-
}
128-
.let { Success(it) }
129-
}
116+
}.let { Success(it) }
130117

131-
fun getMetadata(): WrapperResult<Serialized> {
132-
return Success(
118+
fun getMetadata(): WrapperResult<Serialized> =
119+
Success(
133120
serializeMetadata(HyperTrack.metadata.toMap()),
134121
)
135-
}
136122

137-
fun getName(): WrapperResult<Serialized> {
138-
return Success(
123+
fun getName(): WrapperResult<Serialized> =
124+
Success(
139125
serializeName(HyperTrack.name),
140126
)
141-
}
142127

143-
fun getOrders(): WrapperResult<Serialized> {
144-
return Success(
128+
fun getOrders(): WrapperResult<Serialized> =
129+
Success(
145130
serializeOrders(HyperTrack.orders.values),
146131
)
147-
}
148132

149-
fun getWorkerHandle(): WrapperResult<Serialized> {
150-
return Success(
133+
fun getWorkerHandle(): WrapperResult<Serialized> =
134+
Success(
151135
serializeWorkerHandle(HyperTrack.workerHandle),
152136
)
153-
}
154137

155-
fun setDynamicPublishableKey(args: Serialized): WrapperResult<Unit> {
156-
return deserializeDynamicPublishableKey(args)
138+
fun setDynamicPublishableKey(args: Serialized): WrapperResult<Unit> =
139+
deserializeDynamicPublishableKey(args)
157140
.mapSuccess { publishableKey ->
158141
HyperTrack.dynamicPublishableKey = publishableKey
159142
}
160-
}
161143

162-
fun setIsAvailable(args: Serialized): WrapperResult<Unit> {
163-
return deserializeIsAvailable(args)
144+
fun setIsAvailable(args: Serialized): WrapperResult<Unit> =
145+
deserializeIsAvailable(args)
164146
.mapSuccess { isAvailable ->
165147
HyperTrack.isAvailable = isAvailable
166148
}
167-
}
168149

169-
fun setIsTracking(args: Serialized): WrapperResult<Unit> {
170-
return deserializeIsTracking(args)
150+
fun setIsTracking(args: Serialized): WrapperResult<Unit> =
151+
deserializeIsTracking(args)
171152
.mapSuccess { isTracking ->
172153
HyperTrack.isTracking = isTracking
173154
}
174-
}
175155

176-
fun setMetadata(args: Serialized): WrapperResult<Unit> {
177-
return deserializeMetadata(args)
156+
fun setMetadata(args: Serialized): WrapperResult<Unit> =
157+
deserializeMetadata(args)
178158
.flatMapSuccess { metadata ->
179159
WrapperResult.tryAsResult {
180160
// TODO: return proper error if JSON is wrong
181161
HyperTrack.metadata = Json.fromMap(metadata)!!
182162
}
183163
}
184-
}
185164

186-
fun setName(args: Serialized): WrapperResult<Unit> {
187-
return deserializeName(args)
165+
fun setName(args: Serialized): WrapperResult<Unit> =
166+
deserializeName(args)
188167
.mapSuccess { name ->
189168
HyperTrack.name = name
190169
}
191-
}
192170

193-
fun setWorkerHandle(args: Serialized): WrapperResult<Unit> {
194-
return deserializeWorkerHandle(args)
171+
fun setWorkerHandle(args: Serialized): WrapperResult<Unit> =
172+
deserializeWorkerHandle(args)
195173
.mapSuccess { workerHandle ->
196174
HyperTrack.workerHandle = workerHandle
197175
}
198-
}
199176
}

0 commit comments

Comments
 (0)