hypertrack-sdk-react-native 13.3.5 → 13.5.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 (48) hide show
  1. package/android/gradle.properties +1 -1
  2. package/android/src/main/java/com/reactnativehypertracksdk/HyperTrackReactNativePlugin.kt +48 -6
  3. package/android/src/main/java/com/reactnativehypertracksdk/common/HyperTrackSdkWrapper.kt +22 -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 +97 -44
  6. package/hypertrack-sdk-react-native.podspec +1 -1
  7. package/ios/HyperTrackReactNativePlugin.m +10 -0
  8. package/ios/HyperTrackReactNativePlugin.swift +51 -4
  9. package/ios/common/HyperTrackSDKWrapper.swift +22 -8
  10. package/ios/common/SDKMethod.swift +3 -0
  11. package/ios/common/Serialization.swift +52 -4
  12. package/lib/commonjs/HyperTrack/HyperTrack.js +95 -1
  13. package/lib/commonjs/HyperTrack/HyperTrack.js.map +1 -1
  14. package/lib/commonjs/HyperTrack/data_types/Order.js +6 -0
  15. package/lib/commonjs/HyperTrack/data_types/Order.js.map +1 -0
  16. package/lib/commonjs/HyperTrack/data_types/internal/OrderInternal.js +6 -0
  17. package/lib/commonjs/HyperTrack/data_types/internal/OrderInternal.js.map +1 -0
  18. package/lib/commonjs/HyperTrack/data_types/internal/OrdersInternal.js +2 -0
  19. package/lib/commonjs/HyperTrack/data_types/internal/OrdersInternal.js.map +1 -0
  20. package/lib/commonjs/HyperTrack/data_types/internal/WorkerHandle.js +2 -0
  21. package/lib/commonjs/HyperTrack/data_types/internal/WorkerHandle.js.map +1 -0
  22. package/lib/commonjs/index.js +0 -66
  23. package/lib/commonjs/index.js.map +1 -1
  24. package/lib/module/HyperTrack/HyperTrack.js +95 -1
  25. package/lib/module/HyperTrack/HyperTrack.js.map +1 -1
  26. package/lib/module/HyperTrack/data_types/Order.js +2 -0
  27. package/lib/module/HyperTrack/data_types/Order.js.map +1 -0
  28. package/lib/module/HyperTrack/data_types/internal/OrderInternal.js +2 -0
  29. package/lib/module/HyperTrack/data_types/internal/OrderInternal.js.map +1 -0
  30. package/lib/module/HyperTrack/data_types/internal/OrdersInternal.js +2 -0
  31. package/lib/module/HyperTrack/data_types/internal/OrdersInternal.js.map +1 -0
  32. package/lib/module/HyperTrack/data_types/internal/WorkerHandle.js +2 -0
  33. package/lib/module/HyperTrack/data_types/internal/WorkerHandle.js.map +1 -0
  34. package/lib/module/index.js +0 -6
  35. package/lib/module/index.js.map +1 -1
  36. package/lib/typescript/HyperTrack/HyperTrack.d.ts +48 -2
  37. package/lib/typescript/HyperTrack/data_types/Order.d.ts +6 -0
  38. package/lib/typescript/HyperTrack/data_types/internal/OrderInternal.d.ts +7 -0
  39. package/lib/typescript/HyperTrack/data_types/internal/OrdersInternal.d.ts +4 -0
  40. package/lib/typescript/HyperTrack/data_types/internal/WorkerHandle.d.ts +4 -0
  41. package/lib/typescript/index.d.ts +7 -6
  42. package/package.json +2 -2
  43. package/src/HyperTrack/HyperTrack.ts +114 -2
  44. package/src/HyperTrack/data_types/Order.ts +7 -0
  45. package/src/HyperTrack/data_types/internal/OrderInternal.ts +8 -0
  46. package/src/HyperTrack/data_types/internal/OrdersInternal.ts +4 -0
  47. package/src/HyperTrack/data_types/internal/WorkerHandle.ts +4 -0
  48. package/src/index.tsx +10 -7
@@ -2,7 +2,7 @@ import {
2
2
  NativeModules,
3
3
  Platform,
4
4
  NativeEventEmitter,
5
- EmitterSubscription,
5
+ type EmitterSubscription,
6
6
  } from 'react-native';
7
7
  import { HyperTrackError } from './data_types/HyperTrackError';
8
8
  import type { IsAvailable } from './data_types/internal/IsAvailable';
@@ -22,12 +22,17 @@ import type { Metadata } from './data_types/internal/Metadata';
22
22
  import type { DynamicPublishableKey } from './data_types/internal/DynamicPublishableKey';
23
23
  import type { OrderStatus } from './data_types/OrderStatus';
24
24
  import type { OrderHandle } from './data_types/internal/OrderHandle';
25
+ import type { WorkerHandle } from './data_types/internal/WorkerHandle';
26
+ import type { Order } from './data_types/Order';
27
+ import type { OrdersInternal } from './data_types/internal/OrdersInternal';
28
+ import type { OrderInternal } from './data_types/internal/OrderInternal';
25
29
 
26
30
  const EVENT_ERRORS = 'errors';
27
31
  const EVENT_IS_AVAILABLE = 'isAvailable';
28
32
  const EVENT_IS_TRACKING = 'isTracking';
29
33
  const EVENT_LOCATE = 'locate';
30
34
  const EVENT_LOCATION = 'location';
35
+ const EVENT_ORDERS = 'orders';
31
36
 
32
37
  const LINKING_ERROR =
33
38
  `The package 'hypertrack-sdk-react-native' doesn't seem to be linked. Make sure: \n\n` +
@@ -292,6 +297,31 @@ export default class HyperTrack {
292
297
  });
293
298
  }
294
299
 
300
+ /**
301
+ * Gets the active orders for the worker. The orders are sorted with the ordering in
302
+ * which the worker should complete them.
303
+ *
304
+ * @returns {Map<string, Order>} Map of orders
305
+ */
306
+ static async getOrders(): Promise<Map<string, Order>> {
307
+ return HyperTrackSdk.getOrders().then((orders: OrdersInternal) => {
308
+ return this.deserializeOrders(orders);
309
+ });
310
+ }
311
+
312
+ /**
313
+ * A primary identifier that uniquely identifies the worker outside of HyperTrack.
314
+ * Example: email, phone number, database id
315
+ * It is usually obtained and set when the worker logs into the app.
316
+ * Set it to an empty string "" when the worker logs out of the app to un-bind the device from the worker and
317
+ * avoid unintentional tracking.
318
+ */
319
+ static async getWorkerHandle(): Promise<string> {
320
+ return HyperTrackSdk.getWorkerHandle().then(
321
+ (workerHandle: WorkerHandle) => workerHandle.value
322
+ );
323
+ }
324
+
295
325
  /**
296
326
  * Requests one-time location update and returns the location once it is available, or error.
297
327
  *
@@ -338,7 +368,7 @@ export default class HyperTrack {
338
368
  /**
339
369
  * Sets the availability of the device for the Nearby search
340
370
  *
341
- * @param availability true when is available or false when unavailable
371
+ * @param isAvailable true when is available or false when unavailable
342
372
  */
343
373
  static setIsAvailable(isAvailable: boolean) {
344
374
  HyperTrackSdk.setIsAvailable({
@@ -383,6 +413,22 @@ export default class HyperTrack {
383
413
  } as Name);
384
414
  }
385
415
 
416
+ /**
417
+ * A primary identifier that uniquely identifies the worker outside of HyperTrack.
418
+ * Example: email, phone number, database id
419
+ * It is usually obtained and set when the worker logs into the app.
420
+ * Set it to an empty string "" when the worker logs out of the app to un-bind the device from the worker and
421
+ * avoid unintentional tracking.
422
+ *
423
+ * @param {string} workerHandle
424
+ */
425
+ static setWorkerHandle(workerHandle: string) {
426
+ HyperTrackSdk.setWorkerHandle({
427
+ type: 'workerHandle',
428
+ value: workerHandle,
429
+ } as WorkerHandle);
430
+ }
431
+
386
432
  /**
387
433
  * Subscribe to tracking errors
388
434
  *
@@ -493,6 +539,29 @@ export default class HyperTrack {
493
539
  );
494
540
  }
495
541
 
542
+ /**
543
+ * Subscribe to changes in the orders assigned to the worker
544
+ *
545
+ * @param listener
546
+ * @returns EmitterSubscription
547
+ * @example
548
+ * ```js
549
+ * const subscription = HyperTrack.subscribeToOrders(orders => {
550
+ * ...
551
+ * })
552
+ *
553
+ * // later, to stop listening
554
+ * subscription.remove()
555
+ * ```
556
+ */
557
+ static subscribeToOrders(
558
+ listener: (orders: Map<string, Order>) => void
559
+ ): EmitterSubscription {
560
+ return EventEmitter.addListener(EVENT_ORDERS, (orders: OrdersInternal) => {
561
+ listener(this.deserializeOrders(orders));
562
+ });
563
+ }
564
+
496
565
  /** @ignore */
497
566
  private static deserializeDynamicPublishableKey(
498
567
  dynamicPublishableKey: DynamicPublishableKey
@@ -523,6 +592,24 @@ export default class HyperTrack {
523
592
  return res;
524
593
  }
525
594
 
595
+ /** @ignore */
596
+ private static deserializeIsInsideGeofence(
597
+ isInsideGeofence: Result<boolean, LocationErrorInternal>
598
+ ): Result<boolean, LocationError> {
599
+ switch (isInsideGeofence.type) {
600
+ case 'success':
601
+ return {
602
+ type: 'success',
603
+ value: isInsideGeofence.value,
604
+ };
605
+ case 'failure':
606
+ return {
607
+ type: 'failure',
608
+ value: this.deserializeLocationError(isInsideGeofence.value),
609
+ };
610
+ }
611
+ }
612
+
526
613
  /** @ignore */
527
614
  private static deserializeLocateResponse(
528
615
  response: Result<LocationInternal, HyperTrackErrorInternal[]>
@@ -617,6 +704,31 @@ export default class HyperTrack {
617
704
  return name.value;
618
705
  }
619
706
 
707
+ /** @ignore */
708
+ private static deserializeOrders(orders: OrdersInternal): Map<string, Order> {
709
+ if (orders.type !== 'orders') {
710
+ throw new Error(`Invalid orders: ${JSON.stringify(orders)}`);
711
+ }
712
+ let result = new Map<string, Order>();
713
+ Object.entries(orders.value)
714
+ .map(([_, value]: [string, OrderInternal]) => {
715
+ return value;
716
+ })
717
+ .sort(
718
+ (first: OrderInternal, second: OrderInternal) =>
719
+ first.index - second.index
720
+ )
721
+ .forEach((orderInternal: OrderInternal) => {
722
+ result.set(orderInternal.orderHandle, {
723
+ orderHandle: orderInternal.orderHandle,
724
+ isInsideGeofence: this.deserializeIsInsideGeofence(
725
+ orderInternal.isInsideGeofence
726
+ ),
727
+ } as Order);
728
+ });
729
+ return result;
730
+ }
731
+
620
732
  /** @ignore */
621
733
  private static isLocation(obj: Location): obj is Location {
622
734
  return (
@@ -0,0 +1,7 @@
1
+ import type { Result } from './Result';
2
+ import type { LocationError } from './LocationError';
3
+
4
+ export type Order = {
5
+ orderHandle: string;
6
+ isInsideGeofence: Result<boolean, LocationError>;
7
+ };
@@ -0,0 +1,8 @@
1
+ import type { Result } from '../Result';
2
+ import type { LocationErrorInternal } from './LocationErrorInternal';
3
+
4
+ export type OrderInternal = {
5
+ orderHandle: string;
6
+ isInsideGeofence: Result<boolean, LocationErrorInternal>;
7
+ index: number;
8
+ };
@@ -0,0 +1,4 @@
1
+ export type OrdersInternal = {
2
+ type: 'orders';
3
+ value: object;
4
+ };
@@ -0,0 +1,4 @@
1
+ export type WorkerHandle = {
2
+ type: 'workerHandle';
3
+ value: string;
4
+ };
package/src/index.tsx CHANGED
@@ -1,14 +1,17 @@
1
1
  import HyperTrack from './HyperTrack/HyperTrack';
2
2
  export default HyperTrack;
3
3
  export { HyperTrack };
4
-
5
4
  export { HyperTrackError } from './HyperTrack/data_types/HyperTrackError';
6
- export {
5
+ export type {
7
6
  NotRunning,
8
7
  Starting,
9
8
  } from './HyperTrack/data_types/internal/LocationErrorInternal';
10
- export { LocationError, Errors } from './HyperTrack/data_types/LocationError';
11
- export { LocationWithDeviation } from './HyperTrack/data_types/LocationWithDeviation';
12
- export { Location } from './HyperTrack/data_types/Location';
13
- export { Result, Success, Failure } from './HyperTrack/data_types/Result';
14
- export { OrderStatus } from './HyperTrack/data_types/OrderStatus';
9
+ export type {
10
+ LocationError,
11
+ Errors,
12
+ } from './HyperTrack/data_types/LocationError';
13
+ export type { LocationWithDeviation } from './HyperTrack/data_types/LocationWithDeviation';
14
+ export type { Location } from './HyperTrack/data_types/Location';
15
+ export type { Order } from './HyperTrack/data_types/Order';
16
+ export type { OrderStatus } from './HyperTrack/data_types/OrderStatus';
17
+ export type { Result, Success, Failure } from './HyperTrack/data_types/Result';