From 25a74071cbc17173ccddcbce51a396f116fc3f3b Mon Sep 17 00:00:00 2001 From: pavel-kuznetsov-hypertrack <78730314+pavel-kuznetsov-hypertrack@users.noreply.github.com> Date: Wed, 24 Apr 2024 19:05:50 +0300 Subject: [PATCH] Update HyperTrack SDK iOS to 5.5.2 and Android to 7.5.3 (#102) Add docs links to addGeotag comments. Fix order handle serialization. Fix Kotlin formatting. --- .editorconfig | 11 +- CHANGELOG.md | 8 + README.md | 4 +- docs/classes/HyperTrack.html | 4 +- docs/enums/HyperTrackError.html | 4 +- docs/index.html | 4 +- docs/modules.html | 4 +- docs/types/Errors.html | 2 +- docs/types/Failure.html | 2 +- docs/types/Location.html | 2 +- docs/types/LocationError.html | 2 +- docs/types/LocationWithDeviation.html | 2 +- docs/types/NotRunning.html | 2 +- docs/types/OrderStatus.html | 2 +- docs/types/Result.html | 2 +- docs/types/Starting.html | 2 +- docs/types/Success.html | 2 +- justfile | 6 +- .../android/gradle.properties | 2 +- .../package.json | 2 +- .../android/gradle.properties | 2 +- .../package.json | 2 +- .../android/gradle.properties | 2 +- .../package.json | 2 +- sdk/android/gradle.properties | 2 +- .../HyperTrackReactNativePlugin.kt | 24 ++- .../ReactNativeSerialization.kt | 4 +- .../common/HyperTrackSdkWrapper.kt | 31 ++- .../common/Serialization.kt | 204 +++++++++--------- .../common/WrapperResult.kt | 7 +- sdk/hypertrack-sdk-react-native.podspec | 2 +- sdk/ios/common/Serialization.swift | 27 ++- sdk/package.json | 2 +- sdk/src/HyperTrack/HyperTrack.ts | 15 +- .../data_types/internal/GeotagData.ts | 4 + .../data_types/internal/OrderHandle.ts | 4 + 36 files changed, 236 insertions(+), 167 deletions(-) create mode 100644 sdk/src/HyperTrack/data_types/internal/OrderHandle.ts diff --git a/.editorconfig b/.editorconfig index 061d074d..183b0d19 100644 --- a/.editorconfig +++ b/.editorconfig @@ -5,15 +5,18 @@ root = true [*] - indent_style = space indent_size = 2 - end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true -[*.{kt,kts}] -indent_style = space +[**/*.{kt,kts}] indent_size = 4 +indent_style = space +ktlint_standard_enum-entry-name-case = disabled +ktlint_standard_max-line-length = disabled +ktlint_standard_no-wildcard-imports = disabled +ktlint_standard_no-consecutive-blank-lines = disabled +ktlint_standard_no-consecutive-comments = disabled diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d952c6f..5efdf8ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [13.3.1] - 2024-04-24 + +### Changed + +- Updated HyperTrack SDK iOS to [5.5.2](https://github.com/hypertrack/sdk-ios/releases/tag/5.5.2) +- Updated HyperTrack SDK Android to [7.5.3](https://github.com/hypertrack/sdk-android/releases/tag/7.5.3) + ## [13.3.0] - 2024-04-19 ### Added @@ -819,3 +826,4 @@ Initial release. [13.2.2]: https://github.com/hypertrack/sdk-react-native/releases/tag/13.2.2 [13.2.3]: https://github.com/hypertrack/sdk-react-native/releases/tag/13.2.3 [13.3.0]: https://github.com/hypertrack/sdk-react-native/releases/tag/13.3.0 +[13.3.1]: https://github.com/hypertrack/sdk-react-native/releases/tag/13.3.1 diff --git a/README.md b/README.md index 774c4d6e..10a1f161 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ [![GitHub](https://img.shields.io/github/license/hypertrack/sdk-react-native?color=orange)](./LICENSE) [![npm](https://img.shields.io/npm/v/hypertrack-sdk-react-native.svg)](https://www.npmjs.com/package/hypertrack-sdk-react-native) -[![iOS SDK](https://img.shields.io/badge/iOS%20SDK-5.5.1-brightgreen.svg)](https://github.com/hypertrack/sdk-ios) -[![Android SDK](https://img.shields.io/badge/Android%20SDK-7.5.2-brightgreen.svg)](https://github.com/hypertrack/sdk-android) +[![iOS SDK](https://img.shields.io/badge/iOS%20SDK-5.5.2-brightgreen.svg)](https://github.com/hypertrack/sdk-ios) +[![Android SDK](https://img.shields.io/badge/Android%20SDK-7.5.3-brightgreen.svg)](https://github.com/hypertrack/sdk-android) [HyperTrack](https://www.hypertrack.com) lets you add live location tracking to your mobile app. Live location is made available along with ongoing activity, tracking controls and tracking outage with reasons. diff --git a/docs/classes/HyperTrack.html b/docs/classes/HyperTrack.html index cc93f485..427ddf92 100644 --- a/docs/classes/HyperTrack.html +++ b/docs/classes/HyperTrack.html @@ -1,4 +1,4 @@ -HyperTrack | HyperTrack React Native SDK API - v13.3.0

Constructors

constructor +HyperTrack | HyperTrack React Native SDK API - v13.3.1

Constructors

Properties

Methods

addGeotag getDeviceId @@ -80,4 +80,4 @@

Parameters

Returns EmitterSubscription

EmitterSubscription

Example

const subscription = HyperTrack.subscribeToLocation(location => {
...
})

// later, to stop listening
subscription.remove()
-
\ No newline at end of file +
\ No newline at end of file diff --git a/docs/enums/HyperTrackError.html b/docs/enums/HyperTrackError.html index f1c7c8f0..e52e8925 100644 --- a/docs/enums/HyperTrackError.html +++ b/docs/enums/HyperTrackError.html @@ -1,4 +1,4 @@ -HyperTrackError | HyperTrack React Native SDK API - v13.3.0

Enumeration Members

blockedFromRunning +HyperTrackError | HyperTrack React Native SDK API - v13.3.1

Enumeration Members

permissionsLocationRestricted: "permissions.location.restricted"

[iOS only] The app is not authorized to use location services.

permissionsNotificationsDenied: "permissions.notifications.denied"

[Android only] The user denied notification permissions needed to display a persistent notification needed for foreground location tracking.

-
\ No newline at end of file +
\ No newline at end of file diff --git a/docs/index.html b/docs/index.html index 97323e87..3eb23308 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1,2 +1,2 @@ -HyperTrack React Native SDK API - v13.3.0

HyperTrack React Native SDK API - v13.3.0

hypertrack-sdk-react-native

The main package for HyperTrack SDK React Native.

-
\ No newline at end of file +HyperTrack React Native SDK API - v13.3.1

HyperTrack React Native SDK API - v13.3.1

hypertrack-sdk-react-native

The main package for HyperTrack SDK React Native.

+
\ No newline at end of file diff --git a/docs/modules.html b/docs/modules.html index 53027a4c..fda2b9ee 100644 --- a/docs/modules.html +++ b/docs/modules.html @@ -1,4 +1,4 @@ -HyperTrack React Native SDK API - v13.3.0

HyperTrack React Native SDK API - v13.3.0

References

default +HyperTrack React Native SDK API - v13.3.1

HyperTrack React Native SDK API - v13.3.1

References

Enumerations

Classes

Type Aliases

Location @@ -11,4 +11,4 @@ Result NotRunning Starting -

References

Renames and re-exports HyperTrack
\ No newline at end of file +

References

Renames and re-exports HyperTrack
\ No newline at end of file diff --git a/docs/types/Errors.html b/docs/types/Errors.html index 2c9af9d0..f45a24e0 100644 --- a/docs/types/Errors.html +++ b/docs/types/Errors.html @@ -1 +1 @@ -Errors | HyperTrack React Native SDK API - v13.3.0
Errors: {
    type: "errors";
    value: HyperTrackError[];
}

Type declaration

\ No newline at end of file +Errors | HyperTrack React Native SDK API - v13.3.1
Errors: {
    type: "errors";
    value: HyperTrackError[];
}

Type declaration

\ No newline at end of file diff --git a/docs/types/Failure.html b/docs/types/Failure.html index 819ff9ad..1232537b 100644 --- a/docs/types/Failure.html +++ b/docs/types/Failure.html @@ -1 +1 @@ -Failure | HyperTrack React Native SDK API - v13.3.0
Failure<F>: {
    type: "failure";
    value: F;
}

Type Parameters

  • F

Type declaration

  • type: "failure"
  • value: F
\ No newline at end of file +Failure | HyperTrack React Native SDK API - v13.3.1
Failure<F>: {
    type: "failure";
    value: F;
}

Type Parameters

  • F

Type declaration

  • type: "failure"
  • value: F
\ No newline at end of file diff --git a/docs/types/Location.html b/docs/types/Location.html index 28943766..4f428103 100644 --- a/docs/types/Location.html +++ b/docs/types/Location.html @@ -1 +1 @@ -Location | HyperTrack React Native SDK API - v13.3.0
Location: {
    latitude: number;
    longitude: number;
}

Type declaration

  • latitude: number
  • longitude: number
\ No newline at end of file +Location | HyperTrack React Native SDK API - v13.3.1
Location: {
    latitude: number;
    longitude: number;
}

Type declaration

  • latitude: number
  • longitude: number
\ No newline at end of file diff --git a/docs/types/LocationError.html b/docs/types/LocationError.html index 70a6c9ba..a293b4c0 100644 --- a/docs/types/LocationError.html +++ b/docs/types/LocationError.html @@ -1 +1 @@ -LocationError | HyperTrack React Native SDK API - v13.3.0
LocationError: NotRunning | Starting | Errors
\ No newline at end of file +LocationError | HyperTrack React Native SDK API - v13.3.1
LocationError: NotRunning | Starting | Errors
\ No newline at end of file diff --git a/docs/types/LocationWithDeviation.html b/docs/types/LocationWithDeviation.html index a1144cd8..b79913ad 100644 --- a/docs/types/LocationWithDeviation.html +++ b/docs/types/LocationWithDeviation.html @@ -1 +1 @@ -LocationWithDeviation | HyperTrack React Native SDK API - v13.3.0
LocationWithDeviation: {
    location: Location;
    deviation: number;
}

Type declaration

\ No newline at end of file +LocationWithDeviation | HyperTrack React Native SDK API - v13.3.1
LocationWithDeviation: {
    location: Location;
    deviation: number;
}

Type declaration

\ No newline at end of file diff --git a/docs/types/NotRunning.html b/docs/types/NotRunning.html index a4a28cb2..277aa9c4 100644 --- a/docs/types/NotRunning.html +++ b/docs/types/NotRunning.html @@ -1 +1 @@ -NotRunning | HyperTrack React Native SDK API - v13.3.0
NotRunning: {
    type: "notRunning";
}

Type declaration

  • type: "notRunning"
\ No newline at end of file +NotRunning | HyperTrack React Native SDK API - v13.3.1
NotRunning: {
    type: "notRunning";
}

Type declaration

  • type: "notRunning"
\ No newline at end of file diff --git a/docs/types/OrderStatus.html b/docs/types/OrderStatus.html index d787ec5d..00feaa9f 100644 --- a/docs/types/OrderStatus.html +++ b/docs/types/OrderStatus.html @@ -1 +1 @@ -OrderStatus | HyperTrack React Native SDK API - v13.3.0
OrderStatus: {
    type: "orderStatusClockIn";
} | {
    type: "orderStatusClockOut";
} | {
    type: "orderStatusCustom";
    value: string;
}

Type declaration

  • type: "orderStatusClockIn"

Type declaration

  • type: "orderStatusClockOut"

Type declaration

  • type: "orderStatusCustom"
  • value: string
\ No newline at end of file +OrderStatus | HyperTrack React Native SDK API - v13.3.1
OrderStatus: {
    type: "orderStatusClockIn";
} | {
    type: "orderStatusClockOut";
} | {
    type: "orderStatusCustom";
    value: string;
}

Type declaration

  • type: "orderStatusClockIn"

Type declaration

  • type: "orderStatusClockOut"

Type declaration

  • type: "orderStatusCustom"
  • value: string
\ No newline at end of file diff --git a/docs/types/Result.html b/docs/types/Result.html index 40443adb..16dc3e8a 100644 --- a/docs/types/Result.html +++ b/docs/types/Result.html @@ -1 +1 @@ -Result | HyperTrack React Native SDK API - v13.3.0
Result<S, F>: Success<S> | Failure<F>

Type Parameters

  • S

  • F

\ No newline at end of file +Result | HyperTrack React Native SDK API - v13.3.1
Result<S, F>: Success<S> | Failure<F>

Type Parameters

  • S

  • F

\ No newline at end of file diff --git a/docs/types/Starting.html b/docs/types/Starting.html index 99b79413..3345b251 100644 --- a/docs/types/Starting.html +++ b/docs/types/Starting.html @@ -1 +1 @@ -Starting | HyperTrack React Native SDK API - v13.3.0
Starting: {
    type: "starting";
}

Type declaration

  • type: "starting"
\ No newline at end of file +Starting | HyperTrack React Native SDK API - v13.3.1
Starting: {
    type: "starting";
}

Type declaration

  • type: "starting"
\ No newline at end of file diff --git a/docs/types/Success.html b/docs/types/Success.html index e8ae1ba3..527eedab 100644 --- a/docs/types/Success.html +++ b/docs/types/Success.html @@ -1 +1 @@ -Success | HyperTrack React Native SDK API - v13.3.0
Success<S>: {
    type: "success";
    value: S;
}

Type Parameters

  • S

Type declaration

  • type: "success"
  • value: S
\ No newline at end of file +Success | HyperTrack React Native SDK API - v13.3.1
Success<S>: {
    type: "success";
    value: S;
}

Type Parameters

  • S

Type declaration

  • type: "success"
  • value: S
\ No newline at end of file diff --git a/justfile b/justfile index 1bfc6fb0..43405004 100644 --- a/justfile +++ b/justfile @@ -2,6 +2,7 @@ alias b := build alias cnm := _clear-node-modules alias d := docs +alias f := format alias gd := get-dependencies alias od := open-docs alias pt := push-tag @@ -41,7 +42,7 @@ _clear-node-modules: rm -rf plugin_android_location_services_google_19_0_1/node_modules rm -rf plugin_android_push_service_firebase/node_modules -docs: +docs: format yarn --cwd sdk docs get-dependencies: @@ -56,6 +57,9 @@ _latest-android: _latest-ios: @curl -s https://cocoapods.org/pods/HyperTrack | grep -m 1 -o -E "HyperTrack {{SEMVER_REGEX}}" | grep -o -E '{{SEMVER_REGEX}}' | head -n 1 +format: + ktlint --format sdk/android/src/main/java/ + open-docs: docs open docs/index.html diff --git a/plugin_android_location_services_google/android/gradle.properties b/plugin_android_location_services_google/android/gradle.properties index 19407b3d..1c69c01f 100644 --- a/plugin_android_location_services_google/android/gradle.properties +++ b/plugin_android_location_services_google/android/gradle.properties @@ -3,4 +3,4 @@ PluginAndroidLocationServicesGoogle_minSdkVersion=21 PluginAndroidLocationServicesGoogle_targetSdkVersion=31 PluginAndroidLocationServicesGoogle_compileSdkVersion=31 PluginAndroidLocationServicesGoogle_ndkversion=21.4.7075529 -PluginAndroidLocationServicesGoogle_HyperTrackSDKVersion=7.5.2 +PluginAndroidLocationServicesGoogle_HyperTrackSDKVersion=7.5.3 diff --git a/plugin_android_location_services_google/package.json b/plugin_android_location_services_google/package.json index 95b7f392..facb47fa 100644 --- a/plugin_android_location_services_google/package.json +++ b/plugin_android_location_services_google/package.json @@ -1,6 +1,6 @@ { "name": "hypertrack-sdk-react-native-plugin-android-location-services-google", - "version": "13.3.0", + "version": "13.3.1", "description": "A wrapper around `Location Services Google` plugin for HyperTrack SDK Android that is used with `hypertrack-sdk-react-native`", "main": "lib/commonjs/index", "module": "lib/module/index", diff --git a/plugin_android_location_services_google_19_0_1/android/gradle.properties b/plugin_android_location_services_google_19_0_1/android/gradle.properties index 2fb9965a..7bf2ef51 100644 --- a/plugin_android_location_services_google_19_0_1/android/gradle.properties +++ b/plugin_android_location_services_google_19_0_1/android/gradle.properties @@ -3,4 +3,4 @@ PluginAndroidLocationServicesGoogle1901_minSdkVersion=21 PluginAndroidLocationServicesGoogle1901_targetSdkVersion=31 PluginAndroidLocationServicesGoogle1901_compileSdkVersion=31 PluginAndroidLocationServicesGoogle1901_ndkversion=21.4.7075529 -PluginAndroidLocationServicesGoogle1901_HyperTrackSDKVersion=7.5.2 +PluginAndroidLocationServicesGoogle1901_HyperTrackSDKVersion=7.5.3 diff --git a/plugin_android_location_services_google_19_0_1/package.json b/plugin_android_location_services_google_19_0_1/package.json index b014a891..9f839c30 100644 --- a/plugin_android_location_services_google_19_0_1/package.json +++ b/plugin_android_location_services_google_19_0_1/package.json @@ -1,6 +1,6 @@ { "name": "hypertrack-sdk-react-native-plugin-android-location-services-google-19-0-1", - "version": "13.3.0", + "version": "13.3.1", "description": "A wrapper around `Location Services Google 19.0.1` plugin for HyperTrack SDK Android that is used with `hypertrack-sdk-react-native`", "main": "lib/commonjs/index", "module": "lib/module/index", diff --git a/plugin_android_push_service_firebase/android/gradle.properties b/plugin_android_push_service_firebase/android/gradle.properties index ec73b8e7..32e75736 100644 --- a/plugin_android_push_service_firebase/android/gradle.properties +++ b/plugin_android_push_service_firebase/android/gradle.properties @@ -3,4 +3,4 @@ PluginAndroidPushServiceFirebase_minSdkVersion=21 PluginAndroidPushServiceFirebase_targetSdkVersion=31 PluginAndroidPushServiceFirebase_compileSdkVersion=31 PluginAndroidPushServiceFirebase_ndkversion=21.4.7075529 -PluginAndroidPushServiceFirebase_HyperTrackSDKVersion=7.5.2 +PluginAndroidPushServiceFirebase_HyperTrackSDKVersion=7.5.3 diff --git a/plugin_android_push_service_firebase/package.json b/plugin_android_push_service_firebase/package.json index 75f9a57b..ae571078 100644 --- a/plugin_android_push_service_firebase/package.json +++ b/plugin_android_push_service_firebase/package.json @@ -1,6 +1,6 @@ { "name": "hypertrack-sdk-react-native-plugin-android-push-service-firebase", - "version": "13.3.0", + "version": "13.3.1", "description": "A wrapper around `Push Service Firebase` plugin for HyperTrack SDK Android that is used with `hypertrack-sdk-react-native`", "main": "lib/commonjs/index", "module": "lib/module/index", diff --git a/sdk/android/gradle.properties b/sdk/android/gradle.properties index bc73442f..d6ce034e 100644 --- a/sdk/android/gradle.properties +++ b/sdk/android/gradle.properties @@ -1,3 +1,3 @@ HyperTrackSdk_kotlinVersion=1.6.21 -HyperTrackSdk_HyperTrackSDKVersion=7.5.2 +HyperTrackSdk_HyperTrackSDKVersion=7.5.3 android.useAndroidX=true diff --git a/sdk/android/src/main/java/com/reactnativehypertracksdk/HyperTrackReactNativePlugin.kt b/sdk/android/src/main/java/com/reactnativehypertracksdk/HyperTrackReactNativePlugin.kt index 616c3017..80ac5b1b 100644 --- a/sdk/android/src/main/java/com/reactnativehypertracksdk/HyperTrackReactNativePlugin.kt +++ b/sdk/android/src/main/java/com/reactnativehypertracksdk/HyperTrackReactNativePlugin.kt @@ -10,13 +10,11 @@ import com.reactnativehypertracksdk.common.Serialization.serializeErrors import com.reactnativehypertracksdk.common.Serialization.serializeIsAvailable import com.reactnativehypertracksdk.common.Serialization.serializeIsTracking import com.reactnativehypertracksdk.common.Serialization.serializeLocateResult -import com.reactnativehypertracksdk.common.Serialization.serializeLocation import com.reactnativehypertracksdk.common.Serialization.serializeLocationResult @ReactModule(name = HyperTrackReactNativePlugin.NAME) class HyperTrackReactNativePlugin(reactContext: ReactApplicationContext?) : ReactContextBaseJavaModule(reactContext) { - private var locateSubscription: HyperTrack.Cancellable? = null private var subscriptions: List? = null @@ -66,7 +64,10 @@ class HyperTrackReactNativePlugin(reactContext: ReactApplicationContext?) : */ @ReactMethod - fun addGeotag(args: ReadableMap, promise: Promise) { + fun addGeotag( + args: ReadableMap, + promise: Promise, + ) { HyperTrackSdkWrapper.addGeotag(args.toHashMap()).toPromise(promise) } @@ -113,9 +114,10 @@ class HyperTrackReactNativePlugin(reactContext: ReactApplicationContext?) : @ReactMethod fun locate(promise: Promise) { locateSubscription?.cancel() - locateSubscription = HyperTrack.locate { - emitEvent(EVENT_LOCATE, serializeLocateResult(it).toWritableMap()) - } + locateSubscription = + HyperTrack.locate { + emitEvent(EVENT_LOCATE, serializeLocateResult(it).toWritableMap()) + } Success(Unit).toPromise(promise) } @@ -172,14 +174,20 @@ class HyperTrackReactNativePlugin(reactContext: ReactApplicationContext?) : } } - private fun emitEvent(event: String, data: WritableMap) { + private fun emitEvent( + event: String, + data: WritableMap, + ) { reactApplicationContext .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java) .emit(event, data) } @Suppress("SameParameterValue") - private fun emitEvent(event: String, data: WritableArray) { + private fun emitEvent( + event: String, + data: WritableArray, + ) { reactApplicationContext .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java) .emit(event, data) diff --git a/sdk/android/src/main/java/com/reactnativehypertracksdk/ReactNativeSerialization.kt b/sdk/android/src/main/java/com/reactnativehypertracksdk/ReactNativeSerialization.kt index 707d4699..3aa874ea 100644 --- a/sdk/android/src/main/java/com/reactnativehypertracksdk/ReactNativeSerialization.kt +++ b/sdk/android/src/main/java/com/reactnativehypertracksdk/ReactNativeSerialization.kt @@ -5,8 +5,8 @@ import com.facebook.react.bridge.Promise import com.facebook.react.bridge.WritableArray import com.facebook.react.bridge.WritableMap import com.reactnativehypertracksdk.common.Failure -import com.reactnativehypertracksdk.common.WrapperResult import com.reactnativehypertracksdk.common.Success +import com.reactnativehypertracksdk.common.WrapperResult @Suppress("UNCHECKED_CAST") internal fun WrapperResult.toPromise(promise: Promise) { @@ -98,7 +98,7 @@ internal fun Map.toWritableMap(): WritableMap { is Double -> { putDouble(key, value) } - + is Float -> { putDouble(key, value.toDouble()) } diff --git a/sdk/android/src/main/java/com/reactnativehypertracksdk/common/HyperTrackSdkWrapper.kt b/sdk/android/src/main/java/com/reactnativehypertracksdk/common/HyperTrackSdkWrapper.kt index 66c54c3d..3bddd732 100644 --- a/sdk/android/src/main/java/com/reactnativehypertracksdk/common/HyperTrackSdkWrapper.kt +++ b/sdk/android/src/main/java/com/reactnativehypertracksdk/common/HyperTrackSdkWrapper.kt @@ -28,20 +28,20 @@ typealias Serialized = Map * It receives serialized params. */ internal object HyperTrackSdkWrapper { - fun addGeotag(args: Serialized): WrapperResult { return deserializeGeotagData(args) .flatMapSuccess { geotag -> // TODO: return proper error if JSON is wrong val geotagMetadata = Json.fromMap(geotag.data)!! - val expectedLocation = geotag - .expectedLocation - ?.let { - HyperTrack.Location( - latitude = it.latitude, - longitude = it.longitude - ) - } + val expectedLocation = + geotag + .expectedLocation + ?.let { + HyperTrack.Location( + latitude = it.latitude, + longitude = it.longitude, + ) + } val orderHandle = geotag.orderHandle val orderStatus = geotag.orderStatus if (expectedLocation != null) { @@ -53,7 +53,7 @@ internal object HyperTrackSdkWrapper { orderHandle = orderHandle, orderStatus = orderStatus, expectedLocation = expectedLocation, - metadata = geotagMetadata + metadata = geotagMetadata, ) } else { HyperTrack.addGeotag(geotagMetadata, expectedLocation) @@ -77,7 +77,7 @@ internal object HyperTrackSdkWrapper { HyperTrack.addGeotag( orderHandle = orderHandle, orderStatus = orderStatus, - metadata = geotagMetadata + metadata = geotagMetadata, ) } else { HyperTrack.addGeotag(geotagMetadata) @@ -103,13 +103,13 @@ internal object HyperTrackSdkWrapper { fun getIsAvailable(): WrapperResult { return Success( - serializeIsAvailable(HyperTrack.isAvailable) + serializeIsAvailable(HyperTrack.isAvailable), ) } fun getIsTracking(): WrapperResult { return Success( - serializeIsTracking(HyperTrack.isTracking) + serializeIsTracking(HyperTrack.isTracking), ) } @@ -127,13 +127,13 @@ internal object HyperTrackSdkWrapper { fun getMetadata(): WrapperResult { return Success( - serializeMetadata(HyperTrack.metadata.toMap()) + serializeMetadata(HyperTrack.metadata.toMap()), ) } fun getName(): WrapperResult { return Success( - serializeName(HyperTrack.name) + serializeName(HyperTrack.name), ) } @@ -174,5 +174,4 @@ internal object HyperTrackSdkWrapper { HyperTrack.name = name } } - } diff --git a/sdk/android/src/main/java/com/reactnativehypertracksdk/common/Serialization.kt b/sdk/android/src/main/java/com/reactnativehypertracksdk/common/Serialization.kt index b0a16eff..66e7cf4a 100644 --- a/sdk/android/src/main/java/com/reactnativehypertracksdk/common/Serialization.kt +++ b/sdk/android/src/main/java/com/reactnativehypertracksdk/common/Serialization.kt @@ -9,7 +9,6 @@ import com.hypertrack.sdk.android.Result * to Map or List where T is any JSON-compatible type */ internal object Serialization { - fun deserializeDynamicPublishableKey(args: Serialized): WrapperResult { return parse(args) { it.assertValue(key = KEY_TYPE, value = TYPE_DYNAMIC_PUBLISHABLE_KEY) @@ -21,27 +20,33 @@ internal object Serialization { fun deserializeGeotagData(map: Map): WrapperResult { return parse(map) { - val data = it - .get>(KEY_GEOTAG_DATA) - .getOrThrow() - val expectedLocationData = it - .getOptional>(KEY_GEOTAG_EXPECTED_LOCATION) - .getOrThrow() - val expectedLocation = expectedLocationData?.let { - deserializeLocation(it).getOrThrow() - } - val orderHandle = it - .getOptional(KEY_GEOTAG_ORDER_HANDLE) - .getOrThrow() - val orderStatusData = it - .getOptional>(KEY_GEOTAG_ORDER_STATUS) - .getOrThrow() + val data = + it + .get>(KEY_GEOTAG_DATA) + .getOrThrow() + val expectedLocationData = + it + .getOptional>(KEY_GEOTAG_EXPECTED_LOCATION) + .getOrThrow() + val expectedLocation = + expectedLocationData?.let { + deserializeLocation(it).getOrThrow() + } + val orderHandleData = + it + .getOptional>(KEY_GEOTAG_ORDER_HANDLE) + .getOrThrow() + val orderHandle = orderHandleData?.let { deserializeOrderHandle(it).getOrThrow() } + val orderStatusData = + it + .getOptional>(KEY_GEOTAG_ORDER_STATUS) + .getOrThrow() val orderStatus = orderStatusData?.let { deserializeOrderStatus(it).getOrThrow() } GeotagData( data = data, expectedLocation = expectedLocation, orderHandle = orderHandle, - orderStatus = orderStatus + orderStatus = orderStatus, ) } } @@ -85,33 +90,34 @@ internal object Serialization { fun serializeDeviceId(deviceId: String): Map { return mapOf( KEY_TYPE to TYPE_DEVICE_ID, - KEY_VALUE to deviceId + KEY_VALUE to deviceId, ) } fun serializeDynamicPublishableKey(publishableKey: String): Serialized { return mapOf( KEY_TYPE to TYPE_DYNAMIC_PUBLISHABLE_KEY, - KEY_VALUE to publishableKey + KEY_VALUE to publishableKey, ) } fun serializeError(error: HyperTrack.Error): Map { return mapOf( KEY_TYPE to TYPE_ERROR, - KEY_VALUE to when (error) { - HyperTrack.Error.BlockedFromRunning -> "blockedFromRunning" - HyperTrack.Error.InvalidPublishableKey -> "invalidPublishableKey" - HyperTrack.Error.Location.Mocked -> "location.mocked" - HyperTrack.Error.Location.ServicesDisabled -> "location.servicesDisabled" - HyperTrack.Error.Location.ServicesUnavailable -> "location.servicesUnavailable" - HyperTrack.Error.Location.SignalLost -> "location.signalLost" - HyperTrack.Error.NoExemptionFromBackgroundStartRestrictions -> "noExemptionFromBackgroundStartRestrictions" - HyperTrack.Error.Permissions.Location.Denied -> "permissions.location.denied" - HyperTrack.Error.Permissions.Location.InsufficientForBackground -> "permissions.location.insufficientForBackground" - HyperTrack.Error.Permissions.Location.ReducedAccuracy -> "permissions.location.reducedAccuracy" - HyperTrack.Error.Permissions.Notifications.Denied -> "permissions.notifications.denied" - } + KEY_VALUE to + when (error) { + HyperTrack.Error.BlockedFromRunning -> "blockedFromRunning" + HyperTrack.Error.InvalidPublishableKey -> "invalidPublishableKey" + HyperTrack.Error.Location.Mocked -> "location.mocked" + HyperTrack.Error.Location.ServicesDisabled -> "location.servicesDisabled" + HyperTrack.Error.Location.ServicesUnavailable -> "location.servicesUnavailable" + HyperTrack.Error.Location.SignalLost -> "location.signalLost" + HyperTrack.Error.NoExemptionFromBackgroundStartRestrictions -> "noExemptionFromBackgroundStartRestrictions" + HyperTrack.Error.Permissions.Location.Denied -> "permissions.location.denied" + HyperTrack.Error.Permissions.Location.InsufficientForBackground -> "permissions.location.insufficientForBackground" + HyperTrack.Error.Permissions.Location.ReducedAccuracy -> "permissions.location.reducedAccuracy" + HyperTrack.Error.Permissions.Notifications.Denied -> "permissions.notifications.denied" + }, ) } @@ -124,20 +130,18 @@ internal object Serialization { fun serializeIsAvailable(isAvailable: Boolean): Map { return mapOf( KEY_TYPE to TYPE_IS_AVAILABLE, - KEY_VALUE to isAvailable + KEY_VALUE to isAvailable, ) } fun serializeIsTracking(isTracking: Boolean): Map { return mapOf( KEY_TYPE to TYPE_IS_TRACKING, - KEY_VALUE to isTracking + KEY_VALUE to isTracking, ) } - fun serializeLocateResult( - locationResult: Result> - ): Map { + fun serializeLocateResult(locationResult: Result>): Map { return when (locationResult) { is Result.Failure -> { serializeFailure(serializeErrors(locationResult.failure)) @@ -149,9 +153,7 @@ internal object Serialization { } } - fun serializeLocationResult( - locationResult: Result - ): Map { + fun serializeLocationResult(locationResult: Result): Map { return when (locationResult) { is Result.Failure -> { serializeLocationErrorFailure(locationResult.failure) @@ -171,54 +173,55 @@ internal object Serialization { return serializeSuccess(serializeLocation(location)) } - fun serializeLocationWithDeviationSuccess( - locationWithDeviation: HyperTrack.LocationWithDeviation, - ): Map { + fun serializeLocationWithDeviationSuccess(locationWithDeviation: HyperTrack.LocationWithDeviation): Map { return serializeSuccess( serializeLocationWithDeviation( - locationWithDeviation - ) + locationWithDeviation, + ), ) } fun serializeLocation(location: HyperTrack.Location): Map { return mapOf( KEY_TYPE to TYPE_LOCATION, - KEY_VALUE to mapOf( - KEY_LATITUDE to location.latitude, - KEY_LONGITUDE to location.longitude - ) + KEY_VALUE to + mapOf( + KEY_LATITUDE to location.latitude, + KEY_LONGITUDE to location.longitude, + ), ) } - fun serializeMetadata(metadata: Map): Map { return mapOf( KEY_TYPE to TYPE_METADATA, - KEY_VALUE to metadata + KEY_VALUE to metadata, ) } fun serializeName(name: String): Map { return mapOf( KEY_TYPE to TYPE_NAME, - KEY_VALUE to name + KEY_VALUE to name, ) } private fun deserializeLocation(map: Map): WrapperResult { return parse(map) { it.assertValue(key = KEY_TYPE, value = TYPE_LOCATION) - val value = it - .get>(KEY_VALUE) - .getOrThrow() - parse(value) { parser -> - val latitude = parser - .get(KEY_LATITUDE) - .getOrThrow() - val longitude = parser - .get(KEY_LONGITUDE) + val value = + it + .get>(KEY_VALUE) .getOrThrow() + parse(value) { parser -> + val latitude = + parser + .get(KEY_LATITUDE) + .getOrThrow() + val longitude = + parser + .get(KEY_LONGITUDE) + .getOrThrow() Location("api").also { it.latitude = latitude it.longitude = longitude @@ -227,52 +230,59 @@ internal object Serialization { } } - private fun deserializeOrderStatus( - map: Map - ): WrapperResult { + private fun deserializeOrderHandle(map: Map): WrapperResult { + return parse(map) { + it.assertValue(key = KEY_TYPE, value = TYPE_ORDER_HANDLE) + it + .get(KEY_VALUE) + .getOrThrow() + } + } + + private fun deserializeOrderStatus(map: Map): WrapperResult { return parse(map) { when (it.get(KEY_TYPE).getOrThrow()) { TYPE_GEOTAG_ORDER_STATUS_CLOCK_IN -> HyperTrack.OrderStatus.ClockIn TYPE_GEOTAG_ORDER_STATUS_CLOCK_OUT -> HyperTrack.OrderStatus.ClockOut - TYPE_GEOTAG_ORDER_STATUS_CUSTOM -> HyperTrack.OrderStatus.Custom( - it.get(KEY_VALUE).getOrThrow() - ) + TYPE_GEOTAG_ORDER_STATUS_CUSTOM -> + HyperTrack.OrderStatus.Custom( + it.get(KEY_VALUE).getOrThrow(), + ) else -> throw Error("Unknown order status: $map") } } } - private fun serializeLocationWithDeviation( - locationWithDeviation: HyperTrack.LocationWithDeviation, - ): Map { + private fun serializeLocationWithDeviation(locationWithDeviation: HyperTrack.LocationWithDeviation): Map { return mapOf( KEY_TYPE to TYPE_LOCATION_WITH_DEVIATION, - KEY_VALUE to mapOf( - KEY_LOCATION to serializeLocation(locationWithDeviation.location), - KEY_DEVIATION to locationWithDeviation.deviation - ) + KEY_VALUE to + mapOf( + KEY_LOCATION to serializeLocation(locationWithDeviation.location), + KEY_DEVIATION to locationWithDeviation.deviation, + ), ) } private fun serializeFailure(failure: List>): Map { return mapOf( KEY_TYPE to TYPE_RESULT_FAILURE, - KEY_VALUE to failure + KEY_VALUE to failure, ) } private fun serializeFailure(failure: Map): Map { return mapOf( KEY_TYPE to TYPE_RESULT_FAILURE, - KEY_VALUE to failure + KEY_VALUE to failure, ) } private fun serializeSuccess(success: Map): Map { return mapOf( KEY_TYPE to TYPE_RESULT_SUCCESS, - KEY_VALUE to success + KEY_VALUE to success, ) } @@ -289,8 +299,9 @@ internal object Serialization { is HyperTrack.LocationError.Errors -> { mapOf( KEY_TYPE to TYPE_LOCATION_ERROR_ERRORS, - KEY_VALUE to locationError.errors - .map { serializeError(it) } + KEY_VALUE to + locationError.errors + .map { serializeError(it) }, ) } } @@ -298,7 +309,7 @@ internal object Serialization { fun parse( source: Map, - parseFunction: (Parser) -> T + parseFunction: (Parser) -> T, ): WrapperResult { val parser = Parser(source) return try { @@ -313,20 +324,18 @@ internal object Serialization { ParsingExceptions(source, parser.exceptions + e) } else { e - } + }, ) } } internal class Parser( - private val source: Map + private val source: Map, ) { private val _exceptions = mutableListOf() val exceptions: List = _exceptions - inline fun get( - key: String - ): WrapperResult { + inline fun get(key: String): WrapperResult { return try { Success(source[key]!! as T) } catch (e: Exception) { @@ -334,14 +343,12 @@ internal object Serialization { ParsingException(key, e) .also { _exceptions.add(it) - } + }, ) } } - inline fun getOptional( - key: String - ): WrapperResult { + inline fun getOptional(key: String): WrapperResult { return try { Success(source[key] as T?) } catch (e: Exception) { @@ -349,14 +356,14 @@ internal object Serialization { ParsingException(key, e) .also { _exceptions.add(it) - } + }, ) } } inline fun assertValue( key: String, - value: Any + value: Any, ) { if (source[key] != value) { _exceptions.add(Exception("Assertion failed: $key != $value")) @@ -366,17 +373,17 @@ internal object Serialization { internal data class ParsingExceptions( val source: Any, - val exceptions: List + val exceptions: List, ) : Throwable( - exceptions.joinToString("\n") - .let { - "Invalid input:\n\n${source}\n\n$it" - } - ) + exceptions.joinToString("\n") + .let { + "Invalid input:\n\n${source}\n\n$it" + }, + ) internal class ParsingException( key: String, - exception: Exception + exception: Exception, ) : Exception("Invalid value for '$key': $exception", exception) private const val KEY_TYPE = "type" @@ -399,6 +406,7 @@ internal object Serialization { private const val TYPE_LOCATION_ERROR_NOT_RUNNING = "notRunning" private const val TYPE_LOCATION_ERROR_STARTING = "starting" + private const val TYPE_ORDER_HANDLE = "orderHandle" private const val TYPE_GEOTAG_ORDER_STATUS_CLOCK_IN = "orderStatusClockIn" private const val TYPE_GEOTAG_ORDER_STATUS_CLOCK_OUT = "orderStatusClockOut" private const val TYPE_GEOTAG_ORDER_STATUS_CUSTOM = "orderStatusCustom" diff --git a/sdk/android/src/main/java/com/reactnativehypertracksdk/common/WrapperResult.kt b/sdk/android/src/main/java/com/reactnativehypertracksdk/common/WrapperResult.kt index 101ecb76..02d3a0ff 100644 --- a/sdk/android/src/main/java/com/reactnativehypertracksdk/common/WrapperResult.kt +++ b/sdk/android/src/main/java/com/reactnativehypertracksdk/common/WrapperResult.kt @@ -1,9 +1,7 @@ package com.reactnativehypertracksdk.common internal sealed class WrapperResult { - fun flatMapSuccess( - onSuccess: (SuccessType) -> WrapperResult - ): WrapperResult { + fun flatMapSuccess(onSuccess: (SuccessType) -> WrapperResult): WrapperResult { return when (this) { is Success -> { onSuccess.invoke(this.success) @@ -32,7 +30,7 @@ internal sealed class WrapperResult { is Success -> this.success is Failure -> throw Exception( "Result unwrapping failed: ${this.failure}", - this.failure + this.failure, ) } } @@ -49,4 +47,5 @@ internal sealed class WrapperResult { } internal data class Success(val success: SuccessType) : WrapperResult() + internal data class Failure(val failure: Throwable) : WrapperResult() diff --git a/sdk/hypertrack-sdk-react-native.podspec b/sdk/hypertrack-sdk-react-native.podspec index 46dd78b4..536e023d 100644 --- a/sdk/hypertrack-sdk-react-native.podspec +++ b/sdk/hypertrack-sdk-react-native.podspec @@ -18,7 +18,7 @@ Pod::Spec.new do |s| s.source_files = "ios/**/*.{h,m,mm,swift}" s.dependency "React-Core" - s.dependency 'HyperTrack', '5.5.1' + s.dependency 'HyperTrack', '5.5.2' # Don't install the dependencies when we run `pod install` in the old architecture. if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then diff --git a/sdk/ios/common/Serialization.swift b/sdk/ios/common/Serialization.swift index e5aea0b0..277a8051 100644 --- a/sdk/ios/common/Serialization.swift +++ b/sdk/ios/common/Serialization.swift @@ -32,7 +32,21 @@ func deserializeGeotagData( guard let data = args[keyGeotagData] as? [String: Any] else { return .failure(.fatalError(getParseError(args, key: keyGeotagData))) } - let orderHandle = args["orderHandle"] as? String + let orderHandleData = args["orderHandle"] as? [String: Any] + let orderHandleResult: Result? = if let orderHandleData = orderHandleData { + deserializeOrderHandle(orderHandleData) + } else { + nil + } + if case let .failure(failure) = orderHandleResult { + return .failure(failure) + } + let orderHandle: String? = if case let .success(orderHandle) = orderHandleResult { + orderHandle + } else { + nil + } + let orderStatusData = args["orderStatus"] as? [String: Any] let orderStatusResult: Result? = if let orderStatusData = orderStatusData { deserializeOrderStatus(orderStatusData) @@ -47,6 +61,7 @@ func deserializeGeotagData( } else { nil } + if let expectedLocationData = args[keyExpectedLocation] as? [String: Any] { let expectedLocation = deserializeLocation(expectedLocationData) switch expectedLocation { @@ -126,6 +141,16 @@ func deserializeName(_ data: [String: Any]) -> Result { return .success(value) } +func deserializeOrderHandle(_ data: [String: Any]) -> Result { + if data[keyType] as? String != "orderHandle" { + return .failure(.fatalError(getParseError(data, key: keyType))) + } + guard let value = data[keyValue] as? String else { + return .failure(.fatalError(getParseError(data, key: keyValue))) + } + return .success(value) +} + func deserializeOrderStatus(_ data: [String: Any]) -> Result { guard let type = data[keyType] as? String else { return .failure(.fatalError(getParseError(data, key: keyType))) diff --git a/sdk/package.json b/sdk/package.json index 7514f73d..ba02f0fd 100644 --- a/sdk/package.json +++ b/sdk/package.json @@ -1,6 +1,6 @@ { "name": "hypertrack-sdk-react-native", - "version": "13.3.0", + "version": "13.3.1", "description": "React Native HyperTrack SDK is a wrapper around native iOS and Android SDKs that allows to integrate HyperTrack into React Native apps.", "main": "lib/commonjs/index", "module": "lib/module/index", diff --git a/sdk/src/HyperTrack/HyperTrack.ts b/sdk/src/HyperTrack/HyperTrack.ts index 10350830..674d4770 100644 --- a/sdk/src/HyperTrack/HyperTrack.ts +++ b/sdk/src/HyperTrack/HyperTrack.ts @@ -21,6 +21,7 @@ import type { LocationWithDeviationInternal } from './data_types/internal/Locati import type { Metadata } from './data_types/internal/Metadata'; import type { DynamicPublishableKey } from './data_types/internal/DynamicPublishableKey'; import type { OrderStatus } from './data_types/OrderStatus'; +import type { OrderHandle } from './data_types/internal/OrderHandle'; const EVENT_ERRORS = 'errors'; const EVENT_IS_AVAILABLE = 'isAvailable'; @@ -51,7 +52,7 @@ export default class HyperTrack { private static locateSubscription: EmitterSubscription | undefined; /** - * Adds a new geotag + * Adds a new geotag. Check [Shift tracking](https://hypertrack.com/docs/shift-tracking) and [Clock In/Out tagging](https://hypertrack.com/docs/clock-inout-tracking) docs to learn how to use Order handle and Order status params. * * @param {string} orderHandle - Order handle * @param {OrderStatus} orderStatus - Order status @@ -65,7 +66,7 @@ export default class HyperTrack { ): Promise>; /** - * Adds a new geotag with expected location + * Adds a new geotag with expected location. Check [Shift tracking](https://hypertrack.com/docs/shift-tracking) and [Clock In/Out tagging](https://hypertrack.com/docs/clock-inout-tracking) docs to learn how to use Order handle and Order status params. * * @param {string} orderHandle - Order handle * @param {OrderStatus} orderStatus - Order status @@ -115,7 +116,10 @@ export default class HyperTrack { ) { // addGeotag(orderHandle: string, orderStatus: OrderStatus, data: Object) return HyperTrackSdk.addGeotag({ - orderHandle: args[0], + orderHandle: { + type: 'orderHandle', + value: args[0], + } as OrderHandle, orderStatus: args[1], data: args[2], expectedLocation: undefined, @@ -134,7 +138,10 @@ export default class HyperTrack { ) { // addGeotag(orderHandle: string, orderStatus: OrderStatus, data: Object, expectedLocation: Location) return HyperTrackSdk.addGeotag({ - orderHandle: args[0], + orderHandle: { + type: 'orderHandle', + value: args[0], + } as OrderHandle, orderStatus: args[1], data: args[2], expectedLocation: { diff --git a/sdk/src/HyperTrack/data_types/internal/GeotagData.ts b/sdk/src/HyperTrack/data_types/internal/GeotagData.ts index e20e6fc5..c7f29073 100644 --- a/sdk/src/HyperTrack/data_types/internal/GeotagData.ts +++ b/sdk/src/HyperTrack/data_types/internal/GeotagData.ts @@ -1,6 +1,10 @@ +import type { OrderStatus } from '../OrderStatus'; import type { LocationInternal } from './LocationInternal'; +import type { OrderHandle } from './OrderHandle'; export type GeotagData = { + orderHandle: OrderHandle; + orderStatus: OrderStatus; data: Object; expectedLocation?: LocationInternal; }; diff --git a/sdk/src/HyperTrack/data_types/internal/OrderHandle.ts b/sdk/src/HyperTrack/data_types/internal/OrderHandle.ts new file mode 100644 index 00000000..1a5cd7fa --- /dev/null +++ b/sdk/src/HyperTrack/data_types/internal/OrderHandle.ts @@ -0,0 +1,4 @@ +export type OrderHandle = { + type: 'orderHandle'; + value: string; +};