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.
Files changed (34) hide show
  1. package/android/gradle.properties +1 -1
  2. package/android/src/main/java/com/reactnativehypertracksdk/HyperTrackReactNativePlugin.kt +18 -0
  3. package/android/src/main/java/com/reactnativehypertracksdk/common/HyperTrackSdkWrapper.kt +26 -0
  4. package/android/src/main/java/com/reactnativehypertracksdk/common/SdkMethod.kt +3 -0
  5. package/android/src/main/java/com/reactnativehypertracksdk/common/Serialization.kt +59 -45
  6. package/hypertrack-sdk-react-native.podspec +1 -1
  7. package/ios/HyperTrackReactNativePlugin.m +11 -0
  8. package/ios/HyperTrackReactNativePlugin.swift +42 -0
  9. package/ios/common/HyperTrackSDKWrapper.swift +21 -0
  10. package/ios/common/SDKMethod.swift +3 -0
  11. package/ios/common/Serialization.swift +23 -2
  12. package/lib/commonjs/HyperTrack/HyperTrack.js +50 -3
  13. package/lib/commonjs/HyperTrack/HyperTrack.js.map +1 -1
  14. package/lib/commonjs/HyperTrack/data_types/Order.js.map +1 -1
  15. package/lib/commonjs/HyperTrack/data_types/internal/AllowMockLocation.js +2 -0
  16. package/lib/commonjs/HyperTrack/data_types/internal/AllowMockLocation.js.map +1 -0
  17. package/lib/commonjs/HyperTrack/data_types/internal/OrderInternal.js +0 -4
  18. package/lib/commonjs/HyperTrack/data_types/internal/OrderInternal.js.map +1 -1
  19. package/lib/module/HyperTrack/HyperTrack.js +50 -3
  20. package/lib/module/HyperTrack/HyperTrack.js.map +1 -1
  21. package/lib/module/HyperTrack/data_types/Order.js.map +1 -1
  22. package/lib/module/HyperTrack/data_types/internal/AllowMockLocation.js +2 -0
  23. package/lib/module/HyperTrack/data_types/internal/AllowMockLocation.js.map +1 -0
  24. package/lib/module/HyperTrack/data_types/internal/OrderInternal.js +1 -1
  25. package/lib/module/HyperTrack/data_types/internal/OrderInternal.js.map +1 -1
  26. package/lib/typescript/HyperTrack/HyperTrack.d.ts +19 -0
  27. package/lib/typescript/HyperTrack/data_types/Order.d.ts +1 -1
  28. package/lib/typescript/HyperTrack/data_types/internal/AllowMockLocation.d.ts +4 -0
  29. package/lib/typescript/HyperTrack/data_types/internal/OrderInternal.d.ts +0 -4
  30. package/package.json +1 -1
  31. package/src/HyperTrack/HyperTrack.ts +66 -10
  32. package/src/HyperTrack/data_types/Order.ts +1 -1
  33. package/src/HyperTrack/data_types/internal/AllowMockLocation.ts +4 -0
  34. package/src/HyperTrack/data_types/internal/OrderInternal.ts +0 -5
@@ -27,6 +27,7 @@ import type { Order } from './data_types/Order';
27
27
  import type { OrdersInternal } from './data_types/internal/OrdersInternal';
28
28
  import type { OrderInternal } from './data_types/internal/OrderInternal';
29
29
  import type { IsInsideGeofence } from './data_types/internal/IsInsideGeofence';
30
+ import type { AllowMockLocation } from './data_types/internal/AllowMockLocation';
30
31
 
31
32
  const EVENT_ERRORS = 'errors';
32
33
  const EVENT_IS_AVAILABLE = 'isAvailable';
@@ -212,6 +213,19 @@ export default class HyperTrack {
212
213
  throw new Error(`Invalid addGeotag() arguments: ${JSON.stringify(args)}`);
213
214
  }
214
215
 
216
+ /**
217
+ * If disallowed, the HyperTrack platform will display and outage if mocked location is detected.
218
+ *
219
+ * @param {boolean} true if mock location is allowed
220
+ */
221
+ static async getAllowMockLocation(): Promise<boolean> {
222
+ return HyperTrackSdk.getAllowMockLocation().then(
223
+ (allowMockLocation: AllowMockLocation) => {
224
+ return this.deserializeAllowMockLocation(allowMockLocation);
225
+ }
226
+ );
227
+ }
228
+
215
229
  /**
216
230
  * Returns a string that is used to uniquely identify the device
217
231
  *
@@ -299,7 +313,7 @@ export default class HyperTrack {
299
313
  }
300
314
 
301
315
  /**
302
- * Gets the active orders for the worker. The orders are sorted with the ordering in
316
+ * Gets the active orders for the worker. The orders are sorted with the ordering in
303
317
  * which the worker should complete them.
304
318
  *
305
319
  * @returns {Map<string, Order>} Map of orders
@@ -359,6 +373,23 @@ export default class HyperTrack {
359
373
  return this.locateSubscription;
360
374
  }
361
375
 
376
+ /**
377
+ * Allows mocking location data.
378
+ *
379
+ * Check the [Test with mock locations](https://hypertrack.com/docs/mock-location) guide for more information.
380
+ *
381
+ * 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.
382
+ * 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.
383
+ *
384
+ * @param true if mock location is allowed
385
+ */
386
+ static async setAllowMockLocation(allow: boolean): Promise<void> {
387
+ HyperTrackSdk.setAllowMockLocation({
388
+ type: 'allowMockLocation',
389
+ value: allow,
390
+ } as AllowMockLocation);
391
+ }
392
+
362
393
  static setDynamicPublishableKey(dynamicPublishableKey: string) {
363
394
  HyperTrackSdk.setDynamicPublishableKey({
364
395
  type: 'dynamicPublishableKey',
@@ -563,6 +594,18 @@ export default class HyperTrack {
563
594
  });
564
595
  }
565
596
 
597
+ /** @ignore */
598
+ private static deserializeAllowMockLocation(
599
+ allowMockLocation: AllowMockLocation
600
+ ): boolean {
601
+ if (allowMockLocation.type !== 'allowMockLocation') {
602
+ throw new Error(
603
+ `Invalid allowMockLocation: ${JSON.stringify(allowMockLocation)}`
604
+ );
605
+ }
606
+ return allowMockLocation.value;
607
+ }
608
+
566
609
  /** @ignore */
567
610
  private static deserializeDynamicPublishableKey(
568
611
  dynamicPublishableKey: DynamicPublishableKey
@@ -595,13 +638,15 @@ export default class HyperTrack {
595
638
 
596
639
  /** @ignore */
597
640
  private static deserializeIsInsideGeofence(
598
- isInsideGeofence: Result<IsInsideGeofence, LocationErrorInternal>,
641
+ isInsideGeofence: Result<IsInsideGeofence, LocationErrorInternal>
599
642
  ): Result<boolean, LocationError> {
600
643
  switch (isInsideGeofence.type) {
601
644
  case 'success':
602
645
  let successValue = isInsideGeofence.value;
603
646
  if (successValue.type !== 'isInsideGeofence') {
604
- throw new Error(`Invalid isInsideGeofence: ${JSON.stringify(successValue)}`);
647
+ throw new Error(
648
+ `Invalid isInsideGeofence: ${JSON.stringify(successValue)}`
649
+ );
605
650
  }
606
651
  return {
607
652
  type: 'success',
@@ -719,16 +764,27 @@ export default class HyperTrack {
719
764
  .map(([_, value]: [string, OrderInternal]) => {
720
765
  return value;
721
766
  })
722
- .sort(
723
- (first: OrderInternal, second: OrderInternal) =>
724
- first.index - second.index
725
- )
767
+ .sort((first: OrderInternal, second: OrderInternal) => {
768
+ if (first.index === undefined || second.index === undefined) {
769
+ throw new Error(
770
+ `Invalid order index: ${JSON.stringify(first)} ${JSON.stringify(
771
+ second
772
+ )}`
773
+ );
774
+ }
775
+ return first.index - second.index;
776
+ })
726
777
  .forEach((orderInternal: OrderInternal) => {
727
778
  result.set(orderInternal.orderHandle, {
728
779
  orderHandle: orderInternal.orderHandle,
729
- isInsideGeofence: this.deserializeIsInsideGeofence(
730
- orderInternal.isInsideGeofence
731
- ),
780
+ isInsideGeofence: async () => {
781
+ const isInsideGeofence =
782
+ await HyperTrackSdk.getOrderIsInsideGeofence({
783
+ type: 'orderHandle',
784
+ value: orderInternal.orderHandle,
785
+ });
786
+ return this.deserializeIsInsideGeofence(isInsideGeofence);
787
+ },
732
788
  } as Order);
733
789
  });
734
790
  return result;
@@ -3,5 +3,5 @@ import type { LocationError } from './LocationError';
3
3
 
4
4
  export type Order = {
5
5
  orderHandle: string;
6
- isInsideGeofence: Result<boolean, LocationError>;
6
+ isInsideGeofence: () => Promise<Result<boolean, LocationError>>;
7
7
  };
@@ -0,0 +1,4 @@
1
+ export type AllowMockLocation = {
2
+ type: 'allowMockLocation';
3
+ value: boolean;
4
+ };
@@ -1,9 +1,4 @@
1
- import type { Result } from '../Result';
2
- import type { IsInsideGeofence } from './IsInsideGeofence';
3
- import type { LocationErrorInternal } from './LocationErrorInternal';
4
-
5
1
  export type OrderInternal = {
6
2
  orderHandle: string;
7
- isInsideGeofence: Result<IsInsideGeofence, LocationErrorInternal>;
8
3
  index: number;
9
4
  };