hypertrack-sdk-react-native 13.4.0 → 13.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/android/gradle.properties +1 -1
  2. package/android/src/main/java/com/reactnativehypertracksdk/HyperTrackReactNativePlugin.kt +72 -37
  3. package/android/src/main/java/com/reactnativehypertracksdk/HyperTrackSdkPackage.kt +3 -6
  4. package/android/src/main/java/com/reactnativehypertracksdk/ReactNativeSerialization.kt +2 -3
  5. package/android/src/main/java/com/reactnativehypertracksdk/common/HyperTrackSdkWrapper.kt +46 -62
  6. package/android/src/main/java/com/reactnativehypertracksdk/common/SdkMethod.kt +1 -0
  7. package/android/src/main/java/com/reactnativehypertracksdk/common/Serialization.kt +115 -113
  8. package/android/src/main/java/com/reactnativehypertracksdk/common/WrapperResult.kt +14 -14
  9. package/hypertrack-sdk-react-native.podspec +1 -1
  10. package/ios/HyperTrackReactNativePlugin.m +4 -1
  11. package/ios/HyperTrackReactNativePlugin.swift +21 -1
  12. package/ios/common/HyperTrackSDKWrapper.swift +4 -0
  13. package/ios/common/SDKMethod.swift +1 -0
  14. package/ios/common/Serialization.swift +30 -0
  15. package/lib/commonjs/HyperTrack/HyperTrack.js +72 -1
  16. package/lib/commonjs/HyperTrack/HyperTrack.js.map +1 -1
  17. package/lib/commonjs/HyperTrack/data_types/Order.js +6 -0
  18. package/lib/commonjs/HyperTrack/data_types/Order.js.map +1 -0
  19. package/lib/commonjs/HyperTrack/data_types/internal/IsInsideGeofence.js +2 -0
  20. package/lib/commonjs/HyperTrack/data_types/internal/IsInsideGeofence.js.map +1 -0
  21. package/lib/commonjs/HyperTrack/data_types/internal/OrderInternal.js +6 -0
  22. package/lib/commonjs/HyperTrack/data_types/internal/OrderInternal.js.map +1 -0
  23. package/lib/commonjs/HyperTrack/data_types/internal/OrdersInternal.js +2 -0
  24. package/lib/commonjs/HyperTrack/data_types/internal/OrdersInternal.js.map +1 -0
  25. package/lib/commonjs/index.js +0 -66
  26. package/lib/commonjs/index.js.map +1 -1
  27. package/lib/module/HyperTrack/HyperTrack.js +72 -1
  28. package/lib/module/HyperTrack/HyperTrack.js.map +1 -1
  29. package/lib/module/HyperTrack/data_types/Order.js +2 -0
  30. package/lib/module/HyperTrack/data_types/Order.js.map +1 -0
  31. package/lib/module/HyperTrack/data_types/internal/IsInsideGeofence.js +2 -0
  32. package/lib/module/HyperTrack/data_types/internal/IsInsideGeofence.js.map +1 -0
  33. package/lib/module/HyperTrack/data_types/internal/OrderInternal.js +2 -0
  34. package/lib/module/HyperTrack/data_types/internal/OrderInternal.js.map +1 -0
  35. package/lib/module/HyperTrack/data_types/internal/OrdersInternal.js +2 -0
  36. package/lib/module/HyperTrack/data_types/internal/OrdersInternal.js.map +1 -0
  37. package/lib/module/index.js +0 -6
  38. package/lib/module/index.js.map +1 -1
  39. package/lib/typescript/HyperTrack/HyperTrack.d.ts +30 -2
  40. package/lib/typescript/HyperTrack/data_types/Order.d.ts +6 -0
  41. package/lib/typescript/HyperTrack/data_types/internal/IsInsideGeofence.d.ts +4 -0
  42. package/lib/typescript/HyperTrack/data_types/internal/OrderInternal.d.ts +8 -0
  43. package/lib/typescript/HyperTrack/data_types/internal/OrdersInternal.d.ts +4 -0
  44. package/lib/typescript/index.d.ts +7 -6
  45. package/package.json +2 -2
  46. package/src/HyperTrack/HyperTrack.ts +89 -2
  47. package/src/HyperTrack/data_types/Order.ts +7 -0
  48. package/src/HyperTrack/data_types/internal/IsInsideGeofence.ts +4 -0
  49. package/src/HyperTrack/data_types/internal/OrderInternal.ts +9 -0
  50. package/src/HyperTrack/data_types/internal/OrdersInternal.ts +4 -0
  51. package/src/index.tsx +10 -7
@@ -9,24 +9,23 @@ 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 deserializeDynamicPublishableKey(args: Serialized): WrapperResult<String> {
13
- return parse(args) {
12
+ fun deserializeDynamicPublishableKey(args: Serialized): WrapperResult<String> =
13
+ parse(args) {
14
14
  it.assertValue<String>(key = KEY_TYPE, value = TYPE_DYNAMIC_PUBLISHABLE_KEY)
15
15
  it
16
16
  .get<String>(KEY_VALUE)
17
17
  .getOrThrow()
18
18
  }
19
- }
20
19
 
21
- fun deserializeGeotagData(map: Map<String, Any?>): WrapperResult<GeotagData> {
22
- return parse(map) {
20
+ fun deserializeGeotagData(map: Serialized): WrapperResult<GeotagData> =
21
+ parse(map) {
23
22
  val data =
24
23
  it
25
- .get<Map<String, Any?>>(KEY_GEOTAG_DATA)
24
+ .get<Serialized>(KEY_GEOTAG_DATA)
26
25
  .getOrThrow()
27
26
  val expectedLocationData =
28
27
  it
29
- .getOptional<Map<String, Any?>>(KEY_GEOTAG_EXPECTED_LOCATION)
28
+ .getOptional<Serialized>(KEY_GEOTAG_EXPECTED_LOCATION)
30
29
  .getOrThrow()
31
30
  val expectedLocation =
32
31
  expectedLocationData?.let {
@@ -34,12 +33,12 @@ internal object Serialization {
34
33
  }
35
34
  val orderHandleData =
36
35
  it
37
- .getOptional<Map<String, Any?>>(KEY_GEOTAG_ORDER_HANDLE)
36
+ .getOptional<Serialized>(KEY_GEOTAG_ORDER_HANDLE)
38
37
  .getOrThrow()
39
38
  val orderHandle = orderHandleData?.let { deserializeOrderHandle(it).getOrThrow() }
40
39
  val orderStatusData =
41
40
  it
42
- .getOptional<Map<String, Any?>>(KEY_GEOTAG_ORDER_STATUS)
41
+ .getOptional<Serialized>(KEY_GEOTAG_ORDER_STATUS)
43
42
  .getOrThrow()
44
43
  val orderStatus = orderStatusData?.let { deserializeOrderStatus(it).getOrThrow() }
45
44
  GeotagData(
@@ -49,69 +48,61 @@ internal object Serialization {
49
48
  orderStatus = orderStatus,
50
49
  )
51
50
  }
52
- }
53
51
 
54
- fun deserializeIsAvailable(isAvailable: Map<String, Any?>): WrapperResult<Boolean> {
55
- return parse(isAvailable) {
52
+ fun deserializeIsAvailable(isAvailable: Serialized): WrapperResult<Boolean> =
53
+ parse(isAvailable) {
56
54
  it.assertValue<String>(key = KEY_TYPE, value = TYPE_IS_AVAILABLE)
57
55
  it
58
56
  .get<Boolean>(KEY_VALUE)
59
57
  .getOrThrow()
60
58
  }
61
- }
62
59
 
63
- fun deserializeIsTracking(isTracking: Map<String, Any?>): WrapperResult<Boolean> {
64
- return parse(isTracking) {
60
+ fun deserializeIsTracking(isTracking: Serialized): WrapperResult<Boolean> =
61
+ parse(isTracking) {
65
62
  it.assertValue<String>(key = KEY_TYPE, value = TYPE_IS_TRACKING)
66
63
  it
67
64
  .get<Boolean>(KEY_VALUE)
68
65
  .getOrThrow()
69
66
  }
70
- }
71
67
 
72
- fun deserializeMetadata(metadata: Map<String, Any?>): WrapperResult<Map<String, Any?>> {
73
- return parse(metadata) {
68
+ fun deserializeMetadata(metadata: Serialized): WrapperResult<Serialized> =
69
+ parse(metadata) {
74
70
  it.assertValue<String>(key = KEY_TYPE, value = TYPE_METADATA)
75
71
  it
76
- .get<Map<String, Any?>>(KEY_VALUE)
72
+ .get<Serialized>(KEY_VALUE)
77
73
  .getOrThrow()
78
74
  }
79
- }
80
75
 
81
- fun deserializeName(name: Map<String, Any?>): WrapperResult<String> {
82
- return parse(name) {
76
+ fun deserializeName(name: Serialized): WrapperResult<String> =
77
+ parse(name) {
83
78
  it.assertValue<String>(key = KEY_TYPE, value = TYPE_NAME)
84
79
  it
85
80
  .get<String>(KEY_VALUE)
86
81
  .getOrThrow()
87
82
  }
88
- }
89
83
 
90
- fun deserializeWorkerHandle(map: Map<String, Any?>): WrapperResult<String> {
91
- return parse(map) {
84
+ fun deserializeWorkerHandle(map: Serialized): WrapperResult<String> =
85
+ parse(map) {
92
86
  it.assertValue<String>(key = KEY_TYPE, value = TYPE_WORKER_HANDLE)
93
87
  it
94
88
  .get<String>(KEY_VALUE)
95
89
  .getOrThrow()
96
90
  }
97
- }
98
91
 
99
- fun serializeDeviceId(deviceId: String): Map<String, Any?> {
100
- return mapOf(
92
+ fun serializeDeviceId(deviceId: String): Serialized =
93
+ mapOf(
101
94
  KEY_TYPE to TYPE_DEVICE_ID,
102
95
  KEY_VALUE to deviceId,
103
96
  )
104
- }
105
97
 
106
- fun serializeDynamicPublishableKey(publishableKey: String): Serialized {
107
- return mapOf(
98
+ fun serializeDynamicPublishableKey(publishableKey: String): Serialized =
99
+ mapOf(
108
100
  KEY_TYPE to TYPE_DYNAMIC_PUBLISHABLE_KEY,
109
101
  KEY_VALUE to publishableKey,
110
102
  )
111
- }
112
103
 
113
- fun serializeError(error: HyperTrack.Error): Map<String, String> {
114
- return mapOf(
104
+ fun serializeError(error: HyperTrack.Error): Map<String, String> =
105
+ mapOf(
115
106
  KEY_TYPE to TYPE_ERROR,
116
107
  KEY_VALUE to
117
108
  when (error) {
@@ -128,30 +119,26 @@ internal object Serialization {
128
119
  HyperTrack.Error.Permissions.Notifications.Denied -> "permissions.notifications.denied"
129
120
  },
130
121
  )
131
- }
132
122
 
133
- fun serializeErrors(errors: Set<HyperTrack.Error>): List<Map<String, String>> {
134
- return errors.map {
123
+ fun serializeErrors(errors: Set<HyperTrack.Error>): List<Map<String, String>> =
124
+ errors.map {
135
125
  serializeError(it)
136
126
  }
137
- }
138
127
 
139
- fun serializeIsAvailable(isAvailable: Boolean): Map<String, Any?> {
140
- return mapOf(
128
+ fun serializeIsAvailable(isAvailable: Boolean): Serialized =
129
+ mapOf(
141
130
  KEY_TYPE to TYPE_IS_AVAILABLE,
142
131
  KEY_VALUE to isAvailable,
143
132
  )
144
- }
145
133
 
146
- fun serializeIsTracking(isTracking: Boolean): Map<String, Any?> {
147
- return mapOf(
134
+ fun serializeIsTracking(isTracking: Boolean): Serialized =
135
+ mapOf(
148
136
  KEY_TYPE to TYPE_IS_TRACKING,
149
137
  KEY_VALUE to isTracking,
150
138
  )
151
- }
152
139
 
153
- fun serializeLocateResult(locationResult: Result<HyperTrack.Location, Set<HyperTrack.Error>>): Map<String, Any?> {
154
- return when (locationResult) {
140
+ fun serializeLocateResult(locationResult: Result<HyperTrack.Location, Set<HyperTrack.Error>>): Serialized =
141
+ when (locationResult) {
155
142
  is Result.Failure -> {
156
143
  serializeFailure(serializeErrors(locationResult.failure))
157
144
  }
@@ -160,10 +147,9 @@ internal object Serialization {
160
147
  serializeLocationSuccess(locationResult.success)
161
148
  }
162
149
  }
163
- }
164
150
 
165
- fun serializeLocationResult(locationResult: Result<HyperTrack.Location, HyperTrack.LocationError>): Map<String, Any?> {
166
- return when (locationResult) {
151
+ fun serializeLocationResult(locationResult: Result<HyperTrack.Location, HyperTrack.LocationError>): Serialized =
152
+ when (locationResult) {
167
153
  is Result.Failure -> {
168
154
  serializeLocationErrorFailure(locationResult.failure)
169
155
  }
@@ -172,62 +158,56 @@ internal object Serialization {
172
158
  serializeLocationSuccess(locationResult.success)
173
159
  }
174
160
  }
175
- }
176
161
 
177
- fun serializeLocationErrorFailure(locationError: HyperTrack.LocationError): Map<String, Any?> {
178
- return serializeFailure(serializeLocationError(locationError))
179
- }
162
+ fun serializeLocationErrorFailure(locationError: HyperTrack.LocationError): Serialized =
163
+ serializeFailure(serializeLocationError(locationError))
180
164
 
181
- fun serializeLocationSuccess(location: HyperTrack.Location): Map<String, Any?> {
182
- return serializeSuccess(serializeLocation(location))
183
- }
165
+ fun serializeLocationSuccess(location: HyperTrack.Location): Serialized = serializeSuccess(serializeLocation(location))
184
166
 
185
- fun serializeLocationWithDeviationSuccess(locationWithDeviation: HyperTrack.LocationWithDeviation): Map<String, Any?> {
186
- return serializeSuccess(
167
+ fun serializeLocationWithDeviationSuccess(locationWithDeviation: HyperTrack.LocationWithDeviation): Serialized =
168
+ serializeSuccess(
187
169
  serializeLocationWithDeviation(
188
170
  locationWithDeviation,
189
171
  ),
190
172
  )
191
- }
192
173
 
193
- fun serializeLocation(location: HyperTrack.Location): Map<String, Any?> {
194
- return mapOf(
195
- KEY_TYPE to TYPE_LOCATION,
196
- KEY_VALUE to
197
- mapOf(
198
- KEY_LATITUDE to location.latitude,
199
- KEY_LONGITUDE to location.longitude,
200
- ),
201
- )
202
- }
203
-
204
- fun serializeMetadata(metadata: Map<String, Any?>): Map<String, Any?> {
205
- return mapOf(
174
+ fun serializeMetadata(metadata: Serialized): Serialized =
175
+ mapOf(
206
176
  KEY_TYPE to TYPE_METADATA,
207
177
  KEY_VALUE to metadata,
208
178
  )
209
- }
210
179
 
211
- fun serializeName(name: String): Map<String, Any?> {
212
- return mapOf(
180
+ fun serializeName(name: String): Serialized =
181
+ mapOf(
213
182
  KEY_TYPE to TYPE_NAME,
214
183
  KEY_VALUE to name,
215
184
  )
216
- }
217
185
 
218
- fun serializeWorkerHandle(workerHandle: String): Map<String, Any?> {
219
- return mapOf(
186
+ fun serializeOrders(orders: Collection<HyperTrack.Order>): Serialized =
187
+ mapOf(
188
+ KEY_TYPE to TYPE_ORDERS,
189
+ KEY_VALUE to
190
+ orders.mapIndexed { index, order ->
191
+ mapOf(
192
+ KEY_ORDER_HANDLE to order.orderHandle,
193
+ KEY_ORDER_INDEX to index,
194
+ KEY_ORDER_IS_INSIDE_GEOFENCE to serializeIsInsideGeofence(order.isInsideGeofence),
195
+ )
196
+ },
197
+ )
198
+
199
+ fun serializeWorkerHandle(workerHandle: String): Serialized =
200
+ mapOf(
220
201
  KEY_TYPE to TYPE_WORKER_HANDLE,
221
202
  KEY_VALUE to workerHandle,
222
203
  )
223
- }
224
204
 
225
- private fun deserializeLocation(map: Map<String, Any?>): WrapperResult<Location> {
226
- return parse(map) {
205
+ private fun deserializeLocation(map: Serialized): WrapperResult<Location> =
206
+ parse(map) {
227
207
  it.assertValue<String>(key = KEY_TYPE, value = TYPE_LOCATION)
228
208
  val value =
229
209
  it
230
- .get<Map<String, Any?>>(KEY_VALUE)
210
+ .get<Serialized>(KEY_VALUE)
231
211
  .getOrThrow()
232
212
  parse(value) { parser ->
233
213
  val latitude =
@@ -244,19 +224,17 @@ internal object Serialization {
244
224
  }
245
225
  }.getOrThrow()
246
226
  }
247
- }
248
227
 
249
- private fun deserializeOrderHandle(map: Map<String, Any?>): WrapperResult<String> {
250
- return parse(map) {
228
+ private fun deserializeOrderHandle(map: Serialized): WrapperResult<String> =
229
+ parse(map) {
251
230
  it.assertValue<String>(key = KEY_TYPE, value = TYPE_ORDER_HANDLE)
252
231
  it
253
232
  .get<String>(KEY_VALUE)
254
233
  .getOrThrow()
255
234
  }
256
- }
257
235
 
258
- private fun deserializeOrderStatus(map: Map<String, Any?>): WrapperResult<HyperTrack.OrderStatus> {
259
- return parse(map) {
236
+ private fun deserializeOrderStatus(map: Serialized): WrapperResult<HyperTrack.OrderStatus> =
237
+ parse(map) {
260
238
  when (it.get<String>(KEY_TYPE).getOrThrow()) {
261
239
  TYPE_GEOTAG_ORDER_STATUS_CLOCK_IN -> HyperTrack.OrderStatus.ClockIn
262
240
  TYPE_GEOTAG_ORDER_STATUS_CLOCK_OUT -> HyperTrack.OrderStatus.ClockOut
@@ -268,10 +246,35 @@ internal object Serialization {
268
246
  else -> throw Error("Unknown order status: $map")
269
247
  }
270
248
  }
271
- }
272
249
 
273
- private fun serializeLocationWithDeviation(locationWithDeviation: HyperTrack.LocationWithDeviation): Map<String, Any?> {
274
- return mapOf(
250
+ private fun serializeIsInsideGeofence(isInsideGeofence: Result<Boolean, HyperTrack.LocationError>): Serialized =
251
+ when (isInsideGeofence) {
252
+ is Result.Failure -> {
253
+ serializeFailure(serializeLocationError(isInsideGeofence.failure))
254
+ }
255
+
256
+ is Result.Success -> {
257
+ serializeSuccess(
258
+ mapOf(
259
+ KEY_TYPE to TYPE_IS_INSIDE_GEOFENCE,
260
+ KEY_VALUE to isInsideGeofence.success,
261
+ ),
262
+ )
263
+ }
264
+ }
265
+
266
+ private fun serializeLocation(location: HyperTrack.Location): Serialized =
267
+ mapOf(
268
+ KEY_TYPE to TYPE_LOCATION,
269
+ KEY_VALUE to
270
+ mapOf(
271
+ KEY_LATITUDE to location.latitude,
272
+ KEY_LONGITUDE to location.longitude,
273
+ ),
274
+ )
275
+
276
+ private fun serializeLocationWithDeviation(locationWithDeviation: HyperTrack.LocationWithDeviation): Serialized =
277
+ mapOf(
275
278
  KEY_TYPE to TYPE_LOCATION_WITH_DEVIATION,
276
279
  KEY_VALUE to
277
280
  mapOf(
@@ -279,31 +282,27 @@ internal object Serialization {
279
282
  KEY_DEVIATION to locationWithDeviation.deviation,
280
283
  ),
281
284
  )
282
- }
283
285
 
284
- private fun serializeFailure(failure: List<Map<String, Any?>>): Map<String, Any?> {
285
- return mapOf(
286
+ private fun serializeFailure(failure: List<Serialized>): Serialized =
287
+ mapOf(
286
288
  KEY_TYPE to TYPE_RESULT_FAILURE,
287
289
  KEY_VALUE to failure,
288
290
  )
289
- }
290
291
 
291
- private fun serializeFailure(failure: Map<String, Any?>): Map<String, Any?> {
292
- return mapOf(
292
+ private fun serializeFailure(failure: Serialized): Serialized =
293
+ mapOf(
293
294
  KEY_TYPE to TYPE_RESULT_FAILURE,
294
295
  KEY_VALUE to failure,
295
296
  )
296
- }
297
297
 
298
- private fun serializeSuccess(success: Map<String, Any?>): Map<String, Any?> {
299
- return mapOf(
298
+ private fun serializeSuccess(success: Serialized): Serialized =
299
+ mapOf(
300
300
  KEY_TYPE to TYPE_RESULT_SUCCESS,
301
301
  KEY_VALUE to success,
302
302
  )
303
- }
304
303
 
305
- private fun serializeLocationError(locationError: HyperTrack.LocationError): Map<String, Any?> {
306
- return when (locationError) {
304
+ private fun serializeLocationError(locationError: HyperTrack.LocationError): Serialized =
305
+ when (locationError) {
307
306
  HyperTrack.LocationError.NotRunning -> {
308
307
  mapOf(KEY_TYPE to TYPE_LOCATION_ERROR_NOT_RUNNING)
309
308
  }
@@ -321,10 +320,9 @@ internal object Serialization {
321
320
  )
322
321
  }
323
322
  }
324
- }
325
323
 
326
324
  fun <T> parse(
327
- source: Map<String, Any?>,
325
+ source: Serialized,
328
326
  parseFunction: (Parser) -> T,
329
327
  ): WrapperResult<T> {
330
328
  val parser = Parser(source)
@@ -346,13 +344,13 @@ internal object Serialization {
346
344
  }
347
345
 
348
346
  internal class Parser(
349
- private val source: Map<String, Any?>,
347
+ private val source: Serialized,
350
348
  ) {
351
349
  private val _exceptions = mutableListOf<Exception>()
352
350
  val exceptions: List<Exception> = _exceptions
353
351
 
354
- inline fun <reified T> get(key: String): WrapperResult<T> {
355
- return try {
352
+ inline fun <reified T> get(key: String): WrapperResult<T> =
353
+ try {
356
354
  Success(source[key]!! as T)
357
355
  } catch (e: Exception) {
358
356
  Failure(
@@ -362,10 +360,9 @@ internal object Serialization {
362
360
  },
363
361
  )
364
362
  }
365
- }
366
363
 
367
- inline fun <reified T> getOptional(key: String): WrapperResult<T?> {
368
- return try {
364
+ inline fun <reified T> getOptional(key: String): WrapperResult<T?> =
365
+ try {
369
366
  Success(source[key] as T?)
370
367
  } catch (e: Exception) {
371
368
  Failure(
@@ -375,7 +372,6 @@ internal object Serialization {
375
372
  },
376
373
  )
377
374
  }
378
- }
379
375
 
380
376
  inline fun <reified T> assertValue(
381
377
  key: String,
@@ -391,7 +387,8 @@ internal object Serialization {
391
387
  val source: Any,
392
388
  val exceptions: List<Exception>,
393
389
  ) : Throwable(
394
- exceptions.joinToString("\n")
390
+ exceptions
391
+ .joinToString("\n")
395
392
  .let {
396
393
  "Invalid input:\n\n${source}\n\n$it"
397
394
  },
@@ -412,11 +409,13 @@ internal object Serialization {
412
409
  private const val TYPE_DYNAMIC_PUBLISHABLE_KEY = "dynamicPublishableKey"
413
410
  private const val TYPE_ERROR = "error"
414
411
  private const val TYPE_IS_AVAILABLE = "isAvailable"
412
+ private const val TYPE_IS_INSIDE_GEOFENCE = "isInsideGeofence"
415
413
  private const val TYPE_IS_TRACKING = "isTracking"
416
414
  private const val TYPE_LOCATION = "location"
417
415
  private const val TYPE_LOCATION_WITH_DEVIATION = "locationWithDeviation"
418
416
  private const val TYPE_METADATA = "metadata"
419
417
  private const val TYPE_NAME = "name"
418
+ private const val TYPE_ORDERS = "orders"
420
419
  private const val TYPE_WORKER_HANDLE = "workerHandle"
421
420
 
422
421
  private const val TYPE_LOCATION_ERROR_ERRORS = "errors"
@@ -436,5 +435,8 @@ internal object Serialization {
436
435
  private const val KEY_GEOTAG_EXPECTED_LOCATION = "expectedLocation"
437
436
  private const val KEY_GEOTAG_ORDER_HANDLE = "orderHandle"
438
437
  private const val KEY_GEOTAG_ORDER_STATUS = "orderStatus"
438
+ private const val KEY_ORDER_IS_INSIDE_GEOFENCE = "isInsideGeofence"
439
439
  private const val KEY_LOCATION = "location"
440
+ private const val KEY_ORDER_HANDLE = "orderHandle"
441
+ private const val KEY_ORDER_INDEX = "orderIndex"
440
442
  }
@@ -1,8 +1,8 @@
1
1
  package com.reactnativehypertracksdk.common
2
2
 
3
3
  internal sealed class WrapperResult<SuccessType> {
4
- fun <MappedSuccess> flatMapSuccess(onSuccess: (SuccessType) -> WrapperResult<MappedSuccess>): WrapperResult<MappedSuccess> {
5
- return when (this) {
4
+ fun <MappedSuccess> flatMapSuccess(onSuccess: (SuccessType) -> WrapperResult<MappedSuccess>): WrapperResult<MappedSuccess> =
5
+ when (this) {
6
6
  is Success -> {
7
7
  onSuccess.invoke(this.success)
8
8
  }
@@ -11,10 +11,9 @@ internal sealed class WrapperResult<SuccessType> {
11
11
  Failure<MappedSuccess>(this.failure)
12
12
  }
13
13
  }
14
- }
15
14
 
16
- fun <MappedSuccess> mapSuccess(onSuccess: (SuccessType) -> MappedSuccess): WrapperResult<MappedSuccess> {
17
- return when (this) {
15
+ fun <MappedSuccess> mapSuccess(onSuccess: (SuccessType) -> MappedSuccess): WrapperResult<MappedSuccess> =
16
+ when (this) {
18
17
  is Success -> {
19
18
  Success(onSuccess.invoke(this.success))
20
19
  }
@@ -23,29 +22,30 @@ internal sealed class WrapperResult<SuccessType> {
23
22
  Failure<MappedSuccess>(this.failure)
24
23
  }
25
24
  }
26
- }
27
25
 
28
- fun getOrThrow(): SuccessType {
29
- return when (this) {
26
+ fun getOrThrow(): SuccessType =
27
+ when (this) {
30
28
  is Success -> this.success
31
29
  is Failure -> throw Exception(
32
30
  "Result unwrapping failed: ${this.failure}",
33
31
  this.failure,
34
32
  )
35
33
  }
36
- }
37
34
 
38
35
  companion object {
39
- fun <SuccessType> tryAsResult(block: () -> SuccessType): WrapperResult<SuccessType> {
40
- return try {
36
+ fun <SuccessType> tryAsResult(block: () -> SuccessType): WrapperResult<SuccessType> =
37
+ try {
41
38
  Success(block.invoke())
42
39
  } catch (e: Exception) {
43
40
  Failure(e)
44
41
  }
45
- }
46
42
  }
47
43
  }
48
44
 
49
- internal data class Success<SuccessType>(val success: SuccessType) : WrapperResult<SuccessType>()
45
+ internal data class Success<SuccessType>(
46
+ val success: SuccessType,
47
+ ) : WrapperResult<SuccessType>()
50
48
 
51
- internal data class Failure<SuccessType>(val failure: Throwable) : WrapperResult<SuccessType>()
49
+ internal data class Failure<SuccessType>(
50
+ val failure: Throwable,
51
+ ) : WrapperResult<SuccessType>()
@@ -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', '5.6.0'
21
+ s.dependency 'HyperTrack', '5.7.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
@@ -37,8 +37,11 @@ RCT_EXTERN_METHOD(getMetadata:(RCTPromiseResolveBlock)resolve
37
37
  RCT_EXTERN_METHOD(getName:(RCTPromiseResolveBlock)resolve
38
38
  rejecter:(RCTPromiseRejectBlock)reject)
39
39
 
40
+ RCT_EXTERN_METHOD(getOrders:(RCTPromiseResolveBlock)resolve
41
+ rejecter:(RCTPromiseRejectBlock)reject)
42
+
40
43
  RCT_EXTERN_METHOD(getWorkerHandle:(RCTPromiseResolveBlock)resolve
41
- rejecter:(RCTPromiseRejectBlock)reject)
44
+ rejecter:(RCTPromiseRejectBlock)reject)
42
45
 
43
46
  RCT_EXTERN_METHOD(locate:(RCTPromiseResolveBlock)resolve
44
47
  rejecter:(RCTPromiseRejectBlock)reject)
@@ -5,6 +5,7 @@ struct Subscriptions {
5
5
  let isAvailableSubscription: HyperTrack.Cancellable
6
6
  let isTrackingSubscription: HyperTrack.Cancellable
7
7
  let errorsSubscription: HyperTrack.Cancellable
8
+ let ordersSubscription: HyperTrack.Cancellable
8
9
  }
9
10
 
10
11
  @objc(HyperTrackReactNativePlugin)
@@ -14,6 +15,7 @@ class HyperTrackReactNativePlugin: RCTEventEmitter {
14
15
  private let eventIsTracking = "isTracking"
15
16
  private let eventLocate = "locate"
16
17
  private let eventLocation = "location"
18
+ private let eventOrders = "orders"
17
19
 
18
20
  private var subscriptions: Subscriptions? = nil
19
21
  private var locateSubscription: HyperTrack.Cancellable? = nil
@@ -29,6 +31,7 @@ class HyperTrackReactNativePlugin: RCTEventEmitter {
29
31
  eventIsTracking,
30
32
  eventLocate,
31
33
  eventLocation,
34
+ eventOrders,
32
35
  ]
33
36
  }
34
37
 
@@ -52,6 +55,8 @@ class HyperTrackReactNativePlugin: RCTEventEmitter {
52
55
  sendEvent(withName: eventErrors, body: serializeErrors(HyperTrack.errors))
53
56
  case eventLocation:
54
57
  sendEvent(withName: eventLocation, body: serializeLocationResult(HyperTrack.location))
58
+ case eventOrders:
59
+ sendEvent(withName: eventOrders, body: serializeOrders(Array(HyperTrack.orders)))
55
60
  default:
56
61
  return
57
62
  }
@@ -168,6 +173,18 @@ class HyperTrackReactNativePlugin: RCTEventEmitter {
168
173
  )
169
174
  }
170
175
 
176
+ @objc func getOrders(
177
+ _ resolve: RCTPromiseResolveBlock,
178
+ rejecter reject: RCTPromiseRejectBlock
179
+ ) {
180
+ sendAsPromise(
181
+ hypertrack_sdk_react_native.getOrders(),
182
+ method: .getOrders,
183
+ resolve,
184
+ reject
185
+ )
186
+ }
187
+
171
188
  @objc func getWorkerHandle(
172
189
  _ resolve: RCTPromiseResolveBlock,
173
190
  rejecter reject: RCTPromiseRejectBlock
@@ -299,7 +316,10 @@ class HyperTrackReactNativePlugin: RCTEventEmitter {
299
316
  let locationSubscription = HyperTrack.subscribeToLocation { locationResult in
300
317
  self.sendEvent(withName: self.eventLocation, body: serializeLocationResult(locationResult))
301
318
  }
302
- return Subscriptions(locationSubscription: locationSubscription, isAvailableSubscription: isAvailableSubscription, isTrackingSubscription: isTrackingSubscription, errorsSubscription: errorsSubscription)
319
+ let ordersSubscription = HyperTrack.subscribeToOrders { orders in
320
+ self.sendEvent(withName: self.eventOrders, body: serializeOrders(Array(orders)))
321
+ }
322
+ return Subscriptions(locationSubscription: locationSubscription, isAvailableSubscription: isAvailableSubscription, isTrackingSubscription: isTrackingSubscription, errorsSubscription: errorsSubscription, ordersSubscription: ordersSubscription)
303
323
  }
304
324
  }
305
325
 
@@ -88,6 +88,10 @@ func getName() -> Result<SuccessResult, FailureResult> {
88
88
  .success(.dict(serializeName(HyperTrack.name)))
89
89
  }
90
90
 
91
+ func getOrders() -> Result<SuccessResult, FailureResult> {
92
+ .success(.dict(serializeOrders(Array(HyperTrack.orders))))
93
+ }
94
+
91
95
  func getWorkerHandle() -> Result<SuccessResult, FailureResult> {
92
96
  .success(.dict(serializeWorkerHandle(HyperTrack.workerHandle)))
93
97
  }
@@ -8,6 +8,7 @@ enum SDKMethod: String {
8
8
  case getLocation
9
9
  case getMetadata
10
10
  case getName
11
+ case getOrders
11
12
  case getWorkerHandle
12
13
  case locate
13
14
  case setDynamicPublishableKey
@@ -250,6 +250,24 @@ func serializeIsAvailable(_ isAvailable: Bool) -> [String: Any] {
250
250
  ]
251
251
  }
252
252
 
253
+ func serializeIsInsideGeofence(_ isInsideGeofence: Result<Bool, HyperTrack.Location.Error>) -> [String: Any] {
254
+ switch isInsideGeofence {
255
+ case let .success(success):
256
+ return [
257
+ keyType: typeSuccess,
258
+ keyValue: [
259
+ keyType: "isInsideGeofence",
260
+ keyValue: success,
261
+ ],
262
+ ]
263
+ case let .failure(failure):
264
+ return [
265
+ keyType: typeFailure,
266
+ keyValue: serializeLocationError(failure),
267
+ ]
268
+ }
269
+ }
270
+
253
271
  func serializeIsTracking(_ isTracking: Bool) -> [String: Any] {
254
272
  return [
255
273
  keyType: typeIsTracking,
@@ -358,6 +376,18 @@ func serializeName(_ name: String) -> [String: Any] {
358
376
  ]
359
377
  }
360
378
 
379
+ func serializeOrders(_ orders: [HyperTrack.Order]) -> [String: Any] {
380
+ return [
381
+ keyType: "orders",
382
+ keyValue: orders.map { order in
383
+ [
384
+ "orderHandle": order.orderHandle,
385
+ "isInsideGeofence": serializeIsInsideGeofence(order.isInsideGeofence),
386
+ ]
387
+ },
388
+ ]
389
+ }
390
+
361
391
  func serializeWorkerHandle(_ workerHandle: String) -> [String: Any] {
362
392
  return [
363
393
  keyType: typeWorkerHandle,