hypertrack-sdk-react-native 13.7.1 → 14.0.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.
- package/android/gradle.properties +1 -1
- package/android/src/main/java/com/reactnativehypertracksdk/HyperTrackReactNativePlugin.kt +18 -0
- package/android/src/main/java/com/reactnativehypertracksdk/common/HyperTrackSdkWrapper.kt +26 -0
- package/android/src/main/java/com/reactnativehypertracksdk/common/SdkMethod.kt +3 -0
- package/android/src/main/java/com/reactnativehypertracksdk/common/Serialization.kt +59 -45
- package/hypertrack-sdk-react-native.podspec +1 -1
- package/ios/HyperTrackReactNativePlugin.m +11 -0
- package/ios/HyperTrackReactNativePlugin.swift +42 -0
- package/ios/common/HyperTrackSDKWrapper.swift +21 -0
- package/ios/common/SDKMethod.swift +3 -0
- package/ios/common/Serialization.swift +23 -2
- package/lib/commonjs/HyperTrack/HyperTrack.js +50 -3
- package/lib/commonjs/HyperTrack/HyperTrack.js.map +1 -1
- package/lib/commonjs/HyperTrack/data_types/Order.js.map +1 -1
- package/lib/commonjs/HyperTrack/data_types/internal/AllowMockLocation.js +2 -0
- package/lib/commonjs/HyperTrack/data_types/internal/AllowMockLocation.js.map +1 -0
- package/lib/commonjs/HyperTrack/data_types/internal/OrderInternal.js +0 -4
- package/lib/commonjs/HyperTrack/data_types/internal/OrderInternal.js.map +1 -1
- package/lib/module/HyperTrack/HyperTrack.js +50 -3
- package/lib/module/HyperTrack/HyperTrack.js.map +1 -1
- package/lib/module/HyperTrack/data_types/Order.js.map +1 -1
- package/lib/module/HyperTrack/data_types/internal/AllowMockLocation.js +2 -0
- package/lib/module/HyperTrack/data_types/internal/AllowMockLocation.js.map +1 -0
- package/lib/module/HyperTrack/data_types/internal/OrderInternal.js +1 -1
- package/lib/module/HyperTrack/data_types/internal/OrderInternal.js.map +1 -1
- package/lib/typescript/HyperTrack/HyperTrack.d.ts +19 -0
- package/lib/typescript/HyperTrack/data_types/Order.d.ts +1 -1
- package/lib/typescript/HyperTrack/data_types/internal/AllowMockLocation.d.ts +4 -0
- package/lib/typescript/HyperTrack/data_types/internal/OrderInternal.d.ts +0 -4
- package/package.json +1 -1
- package/src/HyperTrack/HyperTrack.ts +66 -10
- package/src/HyperTrack/data_types/Order.ts +1 -1
- package/src/HyperTrack/data_types/internal/AllowMockLocation.ts +4 -0
- package/src/HyperTrack/data_types/internal/OrderInternal.ts +0 -5
|
@@ -90,6 +90,11 @@ class HyperTrackReactNativePlugin(
|
|
|
90
90
|
HyperTrackSdkWrapper.addGeotag(args.toHashMap()).toPromise(promise)
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
+
@ReactMethod
|
|
94
|
+
fun getAllowMockLocation(promise: Promise) {
|
|
95
|
+
HyperTrackSdkWrapper.getAllowMockLocation().toPromise(promise)
|
|
96
|
+
}
|
|
97
|
+
|
|
93
98
|
@ReactMethod
|
|
94
99
|
fun getDeviceId(promise: Promise) {
|
|
95
100
|
HyperTrackSdkWrapper.getDeviceId().toPromise(promise)
|
|
@@ -130,6 +135,14 @@ class HyperTrackReactNativePlugin(
|
|
|
130
135
|
HyperTrackSdkWrapper.getName().toPromise(promise)
|
|
131
136
|
}
|
|
132
137
|
|
|
138
|
+
@ReactMethod
|
|
139
|
+
fun getOrderIsInsideGeofence(
|
|
140
|
+
args: ReadableMap,
|
|
141
|
+
promise: Promise,
|
|
142
|
+
) {
|
|
143
|
+
HyperTrackSdkWrapper.getOrderIsInsideGeofence(args.toHashMap()).toPromise(promise)
|
|
144
|
+
}
|
|
145
|
+
|
|
133
146
|
@ReactMethod
|
|
134
147
|
fun getOrders(promise: Promise) {
|
|
135
148
|
HyperTrackSdkWrapper.getOrders().toPromise(promise)
|
|
@@ -150,6 +163,11 @@ class HyperTrackReactNativePlugin(
|
|
|
150
163
|
Success(Unit).toPromise(promise)
|
|
151
164
|
}
|
|
152
165
|
|
|
166
|
+
@ReactMethod
|
|
167
|
+
fun setAllowMockLocation(args: ReadableMap) {
|
|
168
|
+
HyperTrackSdkWrapper.setAllowMockLocation(args.toHashMap())
|
|
169
|
+
}
|
|
170
|
+
|
|
153
171
|
@ReactMethod
|
|
154
172
|
fun setDynamicPublishableKey(args: ReadableMap) {
|
|
155
173
|
HyperTrackSdkWrapper.setDynamicPublishableKey(args.toHashMap())
|
|
@@ -3,17 +3,21 @@ package com.reactnativehypertracksdk.common
|
|
|
3
3
|
import com.hypertrack.sdk.android.HyperTrack
|
|
4
4
|
import com.hypertrack.sdk.android.Json
|
|
5
5
|
import com.hypertrack.sdk.android.Result
|
|
6
|
+
import com.reactnativehypertracksdk.common.Serialization.deserializeAllowMockLocation
|
|
6
7
|
import com.reactnativehypertracksdk.common.Serialization.deserializeDynamicPublishableKey
|
|
7
8
|
import com.reactnativehypertracksdk.common.Serialization.deserializeGeotagData
|
|
8
9
|
import com.reactnativehypertracksdk.common.Serialization.deserializeIsAvailable
|
|
9
10
|
import com.reactnativehypertracksdk.common.Serialization.deserializeIsTracking
|
|
10
11
|
import com.reactnativehypertracksdk.common.Serialization.deserializeMetadata
|
|
11
12
|
import com.reactnativehypertracksdk.common.Serialization.deserializeName
|
|
13
|
+
import com.reactnativehypertracksdk.common.Serialization.deserializeOrderHandle
|
|
12
14
|
import com.reactnativehypertracksdk.common.Serialization.deserializeWorkerHandle
|
|
15
|
+
import com.reactnativehypertracksdk.common.Serialization.serializeAllowMockLocation
|
|
13
16
|
import com.reactnativehypertracksdk.common.Serialization.serializeDeviceId
|
|
14
17
|
import com.reactnativehypertracksdk.common.Serialization.serializeDynamicPublishableKey
|
|
15
18
|
import com.reactnativehypertracksdk.common.Serialization.serializeErrors
|
|
16
19
|
import com.reactnativehypertracksdk.common.Serialization.serializeIsAvailable
|
|
20
|
+
import com.reactnativehypertracksdk.common.Serialization.serializeIsInsideGeofence
|
|
17
21
|
import com.reactnativehypertracksdk.common.Serialization.serializeIsTracking
|
|
18
22
|
import com.reactnativehypertracksdk.common.Serialization.serializeLocationErrorFailure
|
|
19
23
|
import com.reactnativehypertracksdk.common.Serialization.serializeLocationResult
|
|
@@ -89,6 +93,8 @@ internal object HyperTrackSdkWrapper {
|
|
|
89
93
|
}
|
|
90
94
|
}
|
|
91
95
|
|
|
96
|
+
fun getAllowMockLocation(): WrapperResult<Serialized> = Success(serializeAllowMockLocation(HyperTrack.allowMockLocation))
|
|
97
|
+
|
|
92
98
|
fun getDeviceId(): WrapperResult<Serialized> = Success(serializeDeviceId(HyperTrack.deviceID))
|
|
93
99
|
|
|
94
100
|
fun getDynamicPublishableKey(): WrapperResult<Serialized> = Success(serializeDynamicPublishableKey(HyperTrack.dynamicPublishableKey))
|
|
@@ -130,11 +136,31 @@ internal object HyperTrackSdkWrapper {
|
|
|
130
136
|
serializeOrders(HyperTrack.orders.values),
|
|
131
137
|
)
|
|
132
138
|
|
|
139
|
+
fun getOrderIsInsideGeofence(args: Serialized): WrapperResult<Serialized> =
|
|
140
|
+
deserializeOrderHandle(args)
|
|
141
|
+
.mapSuccess { orderHandle ->
|
|
142
|
+
HyperTrack
|
|
143
|
+
.orders
|
|
144
|
+
.values
|
|
145
|
+
.firstOrNull { it.orderHandle == orderHandle }
|
|
146
|
+
.let { order ->
|
|
147
|
+
order?.isInsideGeofence ?: Result.Success(false)
|
|
148
|
+
}.let {
|
|
149
|
+
serializeIsInsideGeofence(it)
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
133
153
|
fun getWorkerHandle(): WrapperResult<Serialized> =
|
|
134
154
|
Success(
|
|
135
155
|
serializeWorkerHandle(HyperTrack.workerHandle),
|
|
136
156
|
)
|
|
137
157
|
|
|
158
|
+
fun setAllowMockLocation(args: Serialized): WrapperResult<Unit> =
|
|
159
|
+
deserializeAllowMockLocation(args)
|
|
160
|
+
.mapSuccess { allowMockLocation ->
|
|
161
|
+
HyperTrack.allowMockLocation = allowMockLocation
|
|
162
|
+
}
|
|
163
|
+
|
|
138
164
|
fun setDynamicPublishableKey(args: Serialized): WrapperResult<Unit> =
|
|
139
165
|
deserializeDynamicPublishableKey(args)
|
|
140
166
|
.mapSuccess { publishableKey ->
|
|
@@ -8,6 +8,7 @@ package com.reactnativehypertracksdk.common
|
|
|
8
8
|
*/
|
|
9
9
|
internal enum class SdkMethod {
|
|
10
10
|
addGeotag,
|
|
11
|
+
getAllowMockLocation,
|
|
11
12
|
getDeviceID,
|
|
12
13
|
getDynamicPublishableKey,
|
|
13
14
|
getErrors,
|
|
@@ -16,9 +17,11 @@ internal enum class SdkMethod {
|
|
|
16
17
|
getLocation,
|
|
17
18
|
getMetadata,
|
|
18
19
|
getName,
|
|
20
|
+
getOrderIsInsideGeofence,
|
|
19
21
|
getOrders,
|
|
20
22
|
getWorkerHandle,
|
|
21
23
|
locate,
|
|
24
|
+
setAllowMockLocation,
|
|
22
25
|
setDynamicPublishableKey,
|
|
23
26
|
setIsAvailable,
|
|
24
27
|
setIsTracking,
|
|
@@ -9,6 +9,14 @@ import com.hypertrack.sdk.android.Result
|
|
|
9
9
|
* to Map<String, T> or List<T> where T is any JSON-compatible type
|
|
10
10
|
*/
|
|
11
11
|
internal object Serialization {
|
|
12
|
+
fun deserializeAllowMockLocation(allowMockLocation: Serialized): WrapperResult<Boolean> =
|
|
13
|
+
parse(allowMockLocation) {
|
|
14
|
+
it.assertValue<String>(key = KEY_TYPE, value = TYPE_ALLOW_MOCK_LOCATION)
|
|
15
|
+
it
|
|
16
|
+
.get<Boolean>(KEY_VALUE)
|
|
17
|
+
.getOrThrow()
|
|
18
|
+
}
|
|
19
|
+
|
|
12
20
|
fun deserializeDynamicPublishableKey(args: Serialized): WrapperResult<String> =
|
|
13
21
|
parse(args) {
|
|
14
22
|
it.assertValue<String>(key = KEY_TYPE, value = TYPE_DYNAMIC_PUBLISHABLE_KEY)
|
|
@@ -81,6 +89,14 @@ internal object Serialization {
|
|
|
81
89
|
.getOrThrow()
|
|
82
90
|
}
|
|
83
91
|
|
|
92
|
+
fun deserializeOrderHandle(map: Serialized): WrapperResult<String> =
|
|
93
|
+
parse(map) {
|
|
94
|
+
it.assertValue<String>(key = KEY_TYPE, value = TYPE_ORDER_HANDLE)
|
|
95
|
+
it
|
|
96
|
+
.get<String>(KEY_VALUE)
|
|
97
|
+
.getOrThrow()
|
|
98
|
+
}
|
|
99
|
+
|
|
84
100
|
fun deserializeWorkerHandle(map: Serialized): WrapperResult<String> =
|
|
85
101
|
parse(map) {
|
|
86
102
|
it.assertValue<String>(key = KEY_TYPE, value = TYPE_WORKER_HANDLE)
|
|
@@ -89,6 +105,12 @@ internal object Serialization {
|
|
|
89
105
|
.getOrThrow()
|
|
90
106
|
}
|
|
91
107
|
|
|
108
|
+
fun serializeAllowMockLocation(allowMockLocation: Boolean): Serialized =
|
|
109
|
+
mapOf(
|
|
110
|
+
KEY_TYPE to TYPE_ALLOW_MOCK_LOCATION,
|
|
111
|
+
KEY_VALUE to allowMockLocation,
|
|
112
|
+
)
|
|
113
|
+
|
|
92
114
|
fun serializeDeviceId(deviceId: String): Serialized =
|
|
93
115
|
mapOf(
|
|
94
116
|
KEY_TYPE to TYPE_DEVICE_ID,
|
|
@@ -125,12 +147,40 @@ internal object Serialization {
|
|
|
125
147
|
serializeError(it)
|
|
126
148
|
}
|
|
127
149
|
|
|
150
|
+
fun serializeFailure(failure: List<Serialized>): Serialized =
|
|
151
|
+
mapOf(
|
|
152
|
+
KEY_TYPE to TYPE_RESULT_FAILURE,
|
|
153
|
+
KEY_VALUE to failure,
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
fun serializeFailure(failure: Serialized): Serialized =
|
|
157
|
+
mapOf(
|
|
158
|
+
KEY_TYPE to TYPE_RESULT_FAILURE,
|
|
159
|
+
KEY_VALUE to failure,
|
|
160
|
+
)
|
|
161
|
+
|
|
128
162
|
fun serializeIsAvailable(isAvailable: Boolean): Serialized =
|
|
129
163
|
mapOf(
|
|
130
164
|
KEY_TYPE to TYPE_IS_AVAILABLE,
|
|
131
165
|
KEY_VALUE to isAvailable,
|
|
132
166
|
)
|
|
133
167
|
|
|
168
|
+
fun serializeIsInsideGeofence(isInsideGeofence: Result<Boolean, HyperTrack.LocationError>): Serialized =
|
|
169
|
+
when (isInsideGeofence) {
|
|
170
|
+
is Result.Failure -> {
|
|
171
|
+
serializeFailure(serializeLocationError(isInsideGeofence.failure))
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
is Result.Success -> {
|
|
175
|
+
serializeSuccess(
|
|
176
|
+
mapOf(
|
|
177
|
+
KEY_TYPE to TYPE_IS_INSIDE_GEOFENCE,
|
|
178
|
+
KEY_VALUE to isInsideGeofence.success,
|
|
179
|
+
),
|
|
180
|
+
)
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
134
184
|
fun serializeIsTracking(isTracking: Boolean): Serialized =
|
|
135
185
|
mapOf(
|
|
136
186
|
KEY_TYPE to TYPE_IS_TRACKING,
|
|
@@ -190,11 +240,17 @@ internal object Serialization {
|
|
|
190
240
|
mapOf(
|
|
191
241
|
KEY_ORDER_HANDLE to order.orderHandle,
|
|
192
242
|
KEY_ORDER_INDEX to index,
|
|
193
|
-
|
|
243
|
+
// beware not to call isInsideGeofence here, it's a computed property
|
|
194
244
|
)
|
|
195
245
|
},
|
|
196
246
|
)
|
|
197
247
|
|
|
248
|
+
fun serializeSuccess(success: Serialized): Serialized =
|
|
249
|
+
mapOf(
|
|
250
|
+
KEY_TYPE to TYPE_RESULT_SUCCESS,
|
|
251
|
+
KEY_VALUE to success,
|
|
252
|
+
)
|
|
253
|
+
|
|
198
254
|
fun serializeWorkerHandle(workerHandle: String): Serialized =
|
|
199
255
|
mapOf(
|
|
200
256
|
KEY_TYPE to TYPE_WORKER_HANDLE,
|
|
@@ -224,14 +280,6 @@ internal object Serialization {
|
|
|
224
280
|
}.getOrThrow()
|
|
225
281
|
}
|
|
226
282
|
|
|
227
|
-
private fun deserializeOrderHandle(map: Serialized): WrapperResult<String> =
|
|
228
|
-
parse(map) {
|
|
229
|
-
it.assertValue<String>(key = KEY_TYPE, value = TYPE_ORDER_HANDLE)
|
|
230
|
-
it
|
|
231
|
-
.get<String>(KEY_VALUE)
|
|
232
|
-
.getOrThrow()
|
|
233
|
-
}
|
|
234
|
-
|
|
235
283
|
private fun deserializeOrderStatus(map: Serialized): WrapperResult<HyperTrack.OrderStatus> =
|
|
236
284
|
parse(map) {
|
|
237
285
|
when (it.get<String>(KEY_TYPE).getOrThrow()) {
|
|
@@ -246,22 +294,6 @@ internal object Serialization {
|
|
|
246
294
|
}
|
|
247
295
|
}
|
|
248
296
|
|
|
249
|
-
private fun serializeIsInsideGeofence(isInsideGeofence: Result<Boolean, HyperTrack.LocationError>): Serialized =
|
|
250
|
-
when (isInsideGeofence) {
|
|
251
|
-
is Result.Failure -> {
|
|
252
|
-
serializeFailure(serializeLocationError(isInsideGeofence.failure))
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
is Result.Success -> {
|
|
256
|
-
serializeSuccess(
|
|
257
|
-
mapOf(
|
|
258
|
-
KEY_TYPE to TYPE_IS_INSIDE_GEOFENCE,
|
|
259
|
-
KEY_VALUE to isInsideGeofence.success,
|
|
260
|
-
),
|
|
261
|
-
)
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
|
|
265
297
|
private fun serializeLocation(location: HyperTrack.Location): Serialized =
|
|
266
298
|
mapOf(
|
|
267
299
|
KEY_TYPE to TYPE_LOCATION,
|
|
@@ -282,24 +314,6 @@ internal object Serialization {
|
|
|
282
314
|
),
|
|
283
315
|
)
|
|
284
316
|
|
|
285
|
-
private fun serializeFailure(failure: List<Serialized>): Serialized =
|
|
286
|
-
mapOf(
|
|
287
|
-
KEY_TYPE to TYPE_RESULT_FAILURE,
|
|
288
|
-
KEY_VALUE to failure,
|
|
289
|
-
)
|
|
290
|
-
|
|
291
|
-
private fun serializeFailure(failure: Serialized): Serialized =
|
|
292
|
-
mapOf(
|
|
293
|
-
KEY_TYPE to TYPE_RESULT_FAILURE,
|
|
294
|
-
KEY_VALUE to failure,
|
|
295
|
-
)
|
|
296
|
-
|
|
297
|
-
private fun serializeSuccess(success: Serialized): Serialized =
|
|
298
|
-
mapOf(
|
|
299
|
-
KEY_TYPE to TYPE_RESULT_SUCCESS,
|
|
300
|
-
KEY_VALUE to success,
|
|
301
|
-
)
|
|
302
|
-
|
|
303
317
|
private fun serializeLocationError(locationError: HyperTrack.LocationError): Serialized =
|
|
304
318
|
when (locationError) {
|
|
305
319
|
HyperTrack.LocationError.NotRunning -> {
|
|
@@ -404,6 +418,7 @@ internal object Serialization {
|
|
|
404
418
|
private const val TYPE_RESULT_FAILURE = "failure"
|
|
405
419
|
private const val TYPE_RESULT_SUCCESS = "success"
|
|
406
420
|
|
|
421
|
+
private const val TYPE_ALLOW_MOCK_LOCATION = "allowMockLocation"
|
|
407
422
|
private const val TYPE_DEVICE_ID = "deviceID"
|
|
408
423
|
private const val TYPE_DYNAMIC_PUBLISHABLE_KEY = "dynamicPublishableKey"
|
|
409
424
|
private const val TYPE_ERROR = "error"
|
|
@@ -434,8 +449,7 @@ internal object Serialization {
|
|
|
434
449
|
private const val KEY_GEOTAG_EXPECTED_LOCATION = "expectedLocation"
|
|
435
450
|
private const val KEY_GEOTAG_ORDER_HANDLE = "orderHandle"
|
|
436
451
|
private const val KEY_GEOTAG_ORDER_STATUS = "orderStatus"
|
|
437
|
-
private const val KEY_ORDER_IS_INSIDE_GEOFENCE = "isInsideGeofence"
|
|
438
452
|
private const val KEY_LOCATION = "location"
|
|
439
453
|
private const val KEY_ORDER_HANDLE = "orderHandle"
|
|
440
|
-
private const val KEY_ORDER_INDEX = "
|
|
454
|
+
private const val KEY_ORDER_INDEX = "index"
|
|
441
455
|
}
|
|
@@ -17,7 +17,7 @@ Pod::Spec.new do |s|
|
|
|
17
17
|
s.source_files = "ios/**/*.{h,m,mm,swift}"
|
|
18
18
|
|
|
19
19
|
s.dependency "React-Core"
|
|
20
|
-
s.dependency 'HyperTrack', '5.
|
|
20
|
+
s.dependency 'HyperTrack', '5.11.0'
|
|
21
21
|
|
|
22
22
|
# Don't install the dependencies when we run `pod install` in the old architecture.
|
|
23
23
|
if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
|
|
@@ -13,6 +13,9 @@ RCT_EXTERN_METHOD(addGeotag:(NSDictionary *)args
|
|
|
13
13
|
resolver:(RCTPromiseResolveBlock)resolve
|
|
14
14
|
rejecter:(RCTPromiseRejectBlock)reject)
|
|
15
15
|
|
|
16
|
+
RCT_EXTERN_METHOD(getAllowMockLocation:(RCTPromiseResolveBlock)resolve
|
|
17
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
18
|
+
|
|
16
19
|
RCT_EXTERN_METHOD(getDeviceId:(RCTPromiseResolveBlock)resolve
|
|
17
20
|
rejecter:(RCTPromiseRejectBlock)reject)
|
|
18
21
|
|
|
@@ -37,6 +40,10 @@ RCT_EXTERN_METHOD(getMetadata:(RCTPromiseResolveBlock)resolve
|
|
|
37
40
|
RCT_EXTERN_METHOD(getName:(RCTPromiseResolveBlock)resolve
|
|
38
41
|
rejecter:(RCTPromiseRejectBlock)reject)
|
|
39
42
|
|
|
43
|
+
RCT_EXTERN_METHOD(getOrderIsInsideGeofence:(NSDictionary *)args
|
|
44
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
45
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
46
|
+
|
|
40
47
|
RCT_EXTERN_METHOD(getOrders:(RCTPromiseResolveBlock)resolve
|
|
41
48
|
rejecter:(RCTPromiseRejectBlock)reject)
|
|
42
49
|
|
|
@@ -46,6 +53,10 @@ RCT_EXTERN_METHOD(getWorkerHandle:(RCTPromiseResolveBlock)resolve
|
|
|
46
53
|
RCT_EXTERN_METHOD(locate:(RCTPromiseResolveBlock)resolve
|
|
47
54
|
rejecter:(RCTPromiseRejectBlock)reject)
|
|
48
55
|
|
|
56
|
+
RCT_EXTERN_METHOD(setAllowMockLocation:(NSDictionary *)args
|
|
57
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
58
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
59
|
+
|
|
49
60
|
RCT_EXTERN_METHOD(setDynamicPublishableKey:(NSDictionary *)args
|
|
50
61
|
resolver:(RCTPromiseResolveBlock)resolve
|
|
51
62
|
rejecter:(RCTPromiseRejectBlock)reject)
|
|
@@ -77,6 +77,18 @@ class HyperTrackReactNativePlugin: RCTEventEmitter {
|
|
|
77
77
|
)
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
+
@objc func getAllowMockLocation(
|
|
81
|
+
_ resolve: RCTPromiseResolveBlock,
|
|
82
|
+
rejecter reject: RCTPromiseRejectBlock
|
|
83
|
+
) {
|
|
84
|
+
sendAsPromise(
|
|
85
|
+
hypertrack_sdk_react_native.getAllowMockLocation(),
|
|
86
|
+
method: .getAllowMockLocation,
|
|
87
|
+
resolve,
|
|
88
|
+
reject
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
|
|
80
92
|
@objc func getDeviceId(
|
|
81
93
|
_ resolve: RCTPromiseResolveBlock,
|
|
82
94
|
rejecter reject: RCTPromiseRejectBlock
|
|
@@ -173,6 +185,21 @@ class HyperTrackReactNativePlugin: RCTEventEmitter {
|
|
|
173
185
|
)
|
|
174
186
|
}
|
|
175
187
|
|
|
188
|
+
@objc func getOrderIsInsideGeofence(
|
|
189
|
+
_ args: NSDictionary,
|
|
190
|
+
resolver resolve: RCTPromiseResolveBlock,
|
|
191
|
+
rejecter reject: RCTPromiseRejectBlock
|
|
192
|
+
) {
|
|
193
|
+
sendAsPromise(
|
|
194
|
+
hypertrack_sdk_react_native.getOrderIsInsideGeofence(
|
|
195
|
+
args as! [String: Any]
|
|
196
|
+
),
|
|
197
|
+
method: .getOrderIsInsideGeofence,
|
|
198
|
+
resolve,
|
|
199
|
+
reject
|
|
200
|
+
)
|
|
201
|
+
}
|
|
202
|
+
|
|
176
203
|
@objc func getOrders(
|
|
177
204
|
_ resolve: RCTPromiseResolveBlock,
|
|
178
205
|
rejecter reject: RCTPromiseRejectBlock
|
|
@@ -215,6 +242,21 @@ class HyperTrackReactNativePlugin: RCTEventEmitter {
|
|
|
215
242
|
)
|
|
216
243
|
}
|
|
217
244
|
|
|
245
|
+
@objc func setAllowMockLocation(
|
|
246
|
+
_ args: NSDictionary,
|
|
247
|
+
resolver resolve: RCTPromiseResolveBlock,
|
|
248
|
+
rejecter reject: RCTPromiseRejectBlock
|
|
249
|
+
) {
|
|
250
|
+
sendAsPromise(
|
|
251
|
+
hypertrack_sdk_react_native.setAllowMockLocation(
|
|
252
|
+
args as! [String: Any]
|
|
253
|
+
),
|
|
254
|
+
method: .setAllowMockLocation,
|
|
255
|
+
resolve,
|
|
256
|
+
reject
|
|
257
|
+
)
|
|
258
|
+
}
|
|
259
|
+
|
|
218
260
|
@objc func setDynamicPublishableKey(
|
|
219
261
|
_ args: NSDictionary,
|
|
220
262
|
resolver resolve: RCTPromiseResolveBlock,
|
|
@@ -56,6 +56,10 @@ func addGeotag(_ args: [String: Any]) -> Result<SuccessResult, FailureResult> {
|
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
func getAllowMockLocation() -> Result<SuccessResult, FailureResult> {
|
|
60
|
+
.success(.dict(serializeAllowMockLocation(HyperTrack.allowMockLocation)))
|
|
61
|
+
}
|
|
62
|
+
|
|
59
63
|
func getDeviceID() -> Result<SuccessResult, FailureResult> {
|
|
60
64
|
.success(.dict(serializeDeviceID(HyperTrack.deviceID)))
|
|
61
65
|
}
|
|
@@ -88,6 +92,16 @@ func getName() -> Result<SuccessResult, FailureResult> {
|
|
|
88
92
|
.success(.dict(serializeName(HyperTrack.name)))
|
|
89
93
|
}
|
|
90
94
|
|
|
95
|
+
func getOrderIsInsideGeofence(_ args: [String: Any]) -> Result<SuccessResult, FailureResult> {
|
|
96
|
+
deserializeOrderHandle(args).flatMap { orderHandle in
|
|
97
|
+
if let order = HyperTrack.orders.first(where: { $0.orderHandle == orderHandle }) {
|
|
98
|
+
return .success(.dict(serializeIsInsideGeofence(order.isInsideGeofence)))
|
|
99
|
+
} else {
|
|
100
|
+
return .success(.dict(serializeIsInsideGeofence(.success(false))))
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
91
105
|
func getOrders() -> Result<SuccessResult, FailureResult> {
|
|
92
106
|
.success(.dict(serializeOrders(Array(HyperTrack.orders))))
|
|
93
107
|
}
|
|
@@ -96,6 +110,13 @@ func getWorkerHandle() -> Result<SuccessResult, FailureResult> {
|
|
|
96
110
|
.success(.dict(serializeWorkerHandle(HyperTrack.workerHandle)))
|
|
97
111
|
}
|
|
98
112
|
|
|
113
|
+
func setAllowMockLocation(_ args: [String: Any]) -> Result<SuccessResult, FailureResult> {
|
|
114
|
+
deserializeAllowMockLocation(args).flatMap { (allowMockLocation: Bool) in
|
|
115
|
+
HyperTrack.allowMockLocation = allowMockLocation
|
|
116
|
+
return .success(.void)
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
99
120
|
func setDynamicPublishableKey(_ args: [String: Any]) -> Result<SuccessResult, FailureResult> {
|
|
100
121
|
deserializeDynamicPublishableKey(args).flatMap { (dynamicPublishableKey: String) in
|
|
101
122
|
HyperTrack.dynamicPublishableKey = dynamicPublishableKey
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
enum SDKMethod: String {
|
|
2
2
|
case addGeotag
|
|
3
|
+
case getAllowMockLocation
|
|
3
4
|
case getDeviceID
|
|
4
5
|
case getDynamicPublishableKey
|
|
5
6
|
case getErrors
|
|
@@ -8,9 +9,11 @@ enum SDKMethod: String {
|
|
|
8
9
|
case getLocation
|
|
9
10
|
case getMetadata
|
|
10
11
|
case getName
|
|
12
|
+
case getOrderIsInsideGeofence
|
|
11
13
|
case getOrders
|
|
12
14
|
case getWorkerHandle
|
|
13
15
|
case locate
|
|
16
|
+
case setAllowMockLocation
|
|
14
17
|
case setDynamicPublishableKey
|
|
15
18
|
case setIsAvailable
|
|
16
19
|
case setIsTracking
|
|
@@ -5,6 +5,7 @@ private let keyGeotagData = "data"
|
|
|
5
5
|
private let keyType = "type"
|
|
6
6
|
private let keyValue = "value"
|
|
7
7
|
|
|
8
|
+
private let typeAllowMockLocation = "allowMockLocation"
|
|
8
9
|
private let typeError = "error"
|
|
9
10
|
private let typeFailure = "failure"
|
|
10
11
|
private let typeIsAvailable = "isAvailable"
|
|
@@ -15,6 +16,18 @@ private let typeName = "name"
|
|
|
15
16
|
private let typeSuccess = "success"
|
|
16
17
|
private let typeWorkerHandle = "workerHandle"
|
|
17
18
|
|
|
19
|
+
func deserializeAllowMockLocation(
|
|
20
|
+
_ args: [String: Any]
|
|
21
|
+
) -> Result<Bool, FailureResult> {
|
|
22
|
+
if args[keyType] as? String != typeAllowMockLocation {
|
|
23
|
+
return .failure(.fatalError(getParseError(args, key: keyType)))
|
|
24
|
+
}
|
|
25
|
+
guard let value = args[keyValue] as? Bool else {
|
|
26
|
+
return .failure(.fatalError(getParseError(args, key: keyValue)))
|
|
27
|
+
}
|
|
28
|
+
return .success(value)
|
|
29
|
+
}
|
|
30
|
+
|
|
18
31
|
func deserializeDynamicPublishableKey(
|
|
19
32
|
_ args: [String: Any]
|
|
20
33
|
) -> Result<String, FailureResult> {
|
|
@@ -181,6 +194,13 @@ func deserializeWorkerHandle(_ data: [String: Any]) -> Result<String, FailureRes
|
|
|
181
194
|
return .success(value)
|
|
182
195
|
}
|
|
183
196
|
|
|
197
|
+
func serializeAllowMockLocation(_ allowMockLocation: Bool) -> [String: Any] {
|
|
198
|
+
return [
|
|
199
|
+
keyType: typeAllowMockLocation,
|
|
200
|
+
keyValue: allowMockLocation,
|
|
201
|
+
]
|
|
202
|
+
}
|
|
203
|
+
|
|
184
204
|
func serializeDeviceID(_ deviceID: String) -> [String: Any] {
|
|
185
205
|
return [
|
|
186
206
|
keyType: "deviceID",
|
|
@@ -379,10 +399,11 @@ func serializeName(_ name: String) -> [String: Any] {
|
|
|
379
399
|
func serializeOrders(_ orders: [HyperTrack.Order]) -> [String: Any] {
|
|
380
400
|
return [
|
|
381
401
|
keyType: "orders",
|
|
382
|
-
keyValue: orders.map { order in
|
|
402
|
+
keyValue: orders.enumerated().map { (index, order) in
|
|
383
403
|
[
|
|
404
|
+
"index": index,
|
|
384
405
|
"orderHandle": order.orderHandle,
|
|
385
|
-
|
|
406
|
+
// beware not to call order.isInsideGeofence here, it is a computed property
|
|
386
407
|
]
|
|
387
408
|
},
|
|
388
409
|
]
|
|
@@ -124,6 +124,17 @@ class HyperTrack {
|
|
|
124
124
|
throw new Error(`Invalid addGeotag() arguments: ${JSON.stringify(args)}`);
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
+
/**
|
|
128
|
+
* If disallowed, the HyperTrack platform will display and outage if mocked location is detected.
|
|
129
|
+
*
|
|
130
|
+
* @param {boolean} true if mock location is allowed
|
|
131
|
+
*/
|
|
132
|
+
static async getAllowMockLocation() {
|
|
133
|
+
return HyperTrackSdk.getAllowMockLocation().then(allowMockLocation => {
|
|
134
|
+
return this.deserializeAllowMockLocation(allowMockLocation);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
127
138
|
/**
|
|
128
139
|
* Returns a string that is used to uniquely identify the device
|
|
129
140
|
*
|
|
@@ -197,7 +208,7 @@ class HyperTrack {
|
|
|
197
208
|
}
|
|
198
209
|
|
|
199
210
|
/**
|
|
200
|
-
* Gets the active orders for the worker. The orders are sorted with the ordering in
|
|
211
|
+
* Gets the active orders for the worker. The orders are sorted with the ordering in
|
|
201
212
|
* which the worker should complete them.
|
|
202
213
|
*
|
|
203
214
|
* @returns {Map<string, Order>} Map of orders
|
|
@@ -250,6 +261,23 @@ class HyperTrack {
|
|
|
250
261
|
HyperTrackSdk.locate();
|
|
251
262
|
return this.locateSubscription;
|
|
252
263
|
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Allows mocking location data.
|
|
267
|
+
*
|
|
268
|
+
* Check the [Test with mock locations](https://hypertrack.com/docs/mock-location) guide for more information.
|
|
269
|
+
*
|
|
270
|
+
* To avoid issues related to race conditions in your code use this API **only if** modifying the compiled `HyperTrackAllowMockLocation` AndroidManifest.xml/Info.plist value is insufficient for your needs.
|
|
271
|
+
* Example: if for some reason you aren't able to recompile with `HyperTrackAllowMockLocation` set to `YES`/`true` for your prod app QA mock location tests and need to set up the value in runtime.
|
|
272
|
+
*
|
|
273
|
+
* @param true if mock location is allowed
|
|
274
|
+
*/
|
|
275
|
+
static async setAllowMockLocation(allow) {
|
|
276
|
+
HyperTrackSdk.setAllowMockLocation({
|
|
277
|
+
type: 'allowMockLocation',
|
|
278
|
+
value: allow
|
|
279
|
+
});
|
|
280
|
+
}
|
|
253
281
|
static setDynamicPublishableKey(dynamicPublishableKey) {
|
|
254
282
|
HyperTrackSdk.setDynamicPublishableKey({
|
|
255
283
|
type: 'dynamicPublishableKey',
|
|
@@ -432,6 +460,14 @@ class HyperTrack {
|
|
|
432
460
|
});
|
|
433
461
|
}
|
|
434
462
|
|
|
463
|
+
/** @ignore */
|
|
464
|
+
static deserializeAllowMockLocation(allowMockLocation) {
|
|
465
|
+
if (allowMockLocation.type !== 'allowMockLocation') {
|
|
466
|
+
throw new Error(`Invalid allowMockLocation: ${JSON.stringify(allowMockLocation)}`);
|
|
467
|
+
}
|
|
468
|
+
return allowMockLocation.value;
|
|
469
|
+
}
|
|
470
|
+
|
|
435
471
|
/** @ignore */
|
|
436
472
|
static deserializeDynamicPublishableKey(dynamicPublishableKey) {
|
|
437
473
|
if (dynamicPublishableKey.type !== 'dynamicPublishableKey') {
|
|
@@ -562,10 +598,21 @@ class HyperTrack {
|
|
|
562
598
|
let result = new Map();
|
|
563
599
|
Object.entries(orders.value).map(([_, value]) => {
|
|
564
600
|
return value;
|
|
565
|
-
}).sort((first, second) =>
|
|
601
|
+
}).sort((first, second) => {
|
|
602
|
+
if (first.index === undefined || second.index === undefined) {
|
|
603
|
+
throw new Error(`Invalid order index: ${JSON.stringify(first)} ${JSON.stringify(second)}`);
|
|
604
|
+
}
|
|
605
|
+
return first.index - second.index;
|
|
606
|
+
}).forEach(orderInternal => {
|
|
566
607
|
result.set(orderInternal.orderHandle, {
|
|
567
608
|
orderHandle: orderInternal.orderHandle,
|
|
568
|
-
isInsideGeofence:
|
|
609
|
+
isInsideGeofence: async () => {
|
|
610
|
+
const isInsideGeofence = await HyperTrackSdk.getOrderIsInsideGeofence({
|
|
611
|
+
type: 'orderHandle',
|
|
612
|
+
value: orderInternal.orderHandle
|
|
613
|
+
});
|
|
614
|
+
return this.deserializeIsInsideGeofence(isInsideGeofence);
|
|
615
|
+
}
|
|
569
616
|
});
|
|
570
617
|
});
|
|
571
618
|
return result;
|