@situm/react-native 3.4.0 → 3.4.2

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 (49) hide show
  1. package/README.md +9 -1
  2. package/android/src/main/java/com/situm/plugin/PluginHelper.java +6 -2
  3. package/android/src/main/java/com/situm/plugin/SitumMapper.java +17 -7
  4. package/ios/SitumPlugin.m +22 -6
  5. package/lib/commonjs/index.js +12 -0
  6. package/lib/commonjs/index.js.map +1 -1
  7. package/lib/commonjs/sdk/index.js +27 -12
  8. package/lib/commonjs/sdk/index.js.map +1 -1
  9. package/lib/commonjs/sdk/types/constants.js +1 -1
  10. package/lib/commonjs/sdk/types/index.js +352 -0
  11. package/lib/commonjs/sdk/types/index.js.map +1 -1
  12. package/lib/commonjs/sdk/utils.js +49 -5
  13. package/lib/commonjs/sdk/utils.js.map +1 -1
  14. package/lib/commonjs/utils/requestPermission.js +2 -15
  15. package/lib/commonjs/utils/requestPermission.js.map +1 -1
  16. package/lib/commonjs/wayfinding/hooks/index.js +6 -8
  17. package/lib/commonjs/wayfinding/hooks/index.js.map +1 -1
  18. package/lib/module/index.js +1 -1
  19. package/lib/module/index.js.map +1 -1
  20. package/lib/module/sdk/index.js +28 -13
  21. package/lib/module/sdk/index.js.map +1 -1
  22. package/lib/module/sdk/types/constants.js +1 -1
  23. package/lib/module/sdk/types/index.js +382 -1
  24. package/lib/module/sdk/types/index.js.map +1 -1
  25. package/lib/module/sdk/utils.js +46 -4
  26. package/lib/module/sdk/utils.js.map +1 -1
  27. package/lib/module/utils/requestPermission.js +2 -15
  28. package/lib/module/utils/requestPermission.js.map +1 -1
  29. package/lib/module/wayfinding/hooks/index.js +6 -8
  30. package/lib/module/wayfinding/hooks/index.js.map +1 -1
  31. package/lib/typescript/src/index.d.ts +1 -1
  32. package/lib/typescript/src/index.d.ts.map +1 -1
  33. package/lib/typescript/src/sdk/index.d.ts +3 -6
  34. package/lib/typescript/src/sdk/index.d.ts.map +1 -1
  35. package/lib/typescript/src/sdk/types/constants.d.ts +1 -1
  36. package/lib/typescript/src/sdk/types/index.d.ts +79 -1
  37. package/lib/typescript/src/sdk/types/index.d.ts.map +1 -1
  38. package/lib/typescript/src/sdk/utils.d.ts +1 -0
  39. package/lib/typescript/src/sdk/utils.d.ts.map +1 -1
  40. package/lib/typescript/src/utils/requestPermission.d.ts.map +1 -1
  41. package/lib/typescript/src/wayfinding/hooks/index.d.ts.map +1 -1
  42. package/package.json +3 -3
  43. package/src/index.ts +1 -1
  44. package/src/sdk/index.ts +52 -32
  45. package/src/sdk/types/constants.ts +1 -1
  46. package/src/sdk/types/index.ts +82 -1
  47. package/src/sdk/utils.ts +42 -2
  48. package/src/utils/requestPermission.ts +2 -19
  49. package/src/wayfinding/hooks/index.ts +11 -4
@@ -496,17 +496,45 @@ export type RealTimeData = {
496
496
  locations: Location[];
497
497
  };
498
498
 
499
+ /**
500
+ * @name SdkVersion
501
+ * @description Represents the version information of the SDK and its compatibility with different platforms.
502
+ *
503
+ * @type
504
+ * @property {string} react_native - The version of React Native used in the SDK.
505
+ * @property {string} [ios] - Optional. The specific version of the Situm SDK for the iOS platform.
506
+ * @property {string} [android] - Optional. The specific version of the Situm SDK for the Android platform.
507
+ */
499
508
  export type SdkVersion = {
500
509
  react_native: string;
501
510
  ios?: string;
502
511
  android?: string;
503
512
  };
504
513
 
514
+ /**
515
+ * @name ConfigurationOptions
516
+ * @description Configuration options for initializing the SDK or other modules.
517
+ *
518
+ * @type
519
+ * @property {boolean} [useRemoteConfig] - Optional. Determines whether to use Remote Configuration settings.
520
+ * @property {number} [cacheMaxAge] - Optional. The maximum age of the cache in seconds.
521
+ */
505
522
  export type ConfigurationOptions = {
506
523
  useRemoteConfig?: boolean;
507
524
  cacheMaxAge?: number;
508
525
  };
509
526
 
527
+ /**
528
+ * @name Location
529
+ * @description Represents a location with various attributes including position, accuracy, and bearing.
530
+ *
531
+ * @interface
532
+ * @property {Position} [position] - Optional. The position information of the location.
533
+ * @property {number} [accuracy] - Optional. The accuracy of the location information in meters.
534
+ * @property {Object} [bearing] - Optional. Bearing information including degrees and degreesClockwise.
535
+ * @property {boolean} [hasBearing] - Optional. Indicates if bearing information is available.
536
+ * @property {LocationStatusName} status - The status of the location update.
537
+ */
510
538
  export interface Location {
511
539
  position?: Position;
512
540
  accuracy?: number;
@@ -532,14 +560,67 @@ export interface Position {
532
560
  buildingIdentifier?: string;
533
561
  floorIdentifier?: string;
534
562
  }
563
+
564
+ /**
565
+ * @name LocationStatus
566
+ * @description Represents the status of a location, including a name and a numeric code.
567
+ *
568
+ * @interface
569
+ * @property {LocationStatusName} statusName - The name of the location status.
570
+ * @property {number} statusCode - The numeric code representing the location status.
571
+ */
535
572
  export interface LocationStatus {
536
573
  statusName: LocationStatusName;
537
574
  statusCode: number;
538
575
  }
539
576
 
577
+ /**
578
+ * @name ErrorType
579
+ * @description Enumeration of error types to categorize the severity of errors.
580
+ *
581
+ * @enum {string}
582
+ * @property {string} CRITICAL - Represents critical errors that will cause the system not to work (e.g. positioning will be stopped).
583
+ * @property {string} NON_CRITICAL - Represents non-critical errors that are less severe.
584
+ */
585
+ export enum ErrorType {
586
+ CRITICAL = "CRITICAL",
587
+ NON_CRITICAL = "NON_CRITICAL",
588
+ }
589
+
590
+ /**
591
+ * @name ErrorCode
592
+ * @description Enumeration of error codes provided by Situm SDK.
593
+ *
594
+ * @enum {string}
595
+ * @property {string} LOCATION_PERMISSION_DENIED - Indicates that location permissions were not granted by the user.
596
+ * @property {string} BLUETOOTH_PERMISSION_DENIED - Indicates that Bluetooth permissions were not granted.
597
+ * @property {string} BLUETOOTH_DISABLED - Indicates that Bluetooth is disabled on the device.
598
+ * @property {string} LOCATION_DISABLED - Indicates that the location services are disabled on the device.
599
+ * @property {string} REDUCED_ACCURACY - Indicates that the precise location has been turned off on the device.
600
+ * @property {string} UNKNOWN - Represents an unknown error or an error that does not fit other categories.
601
+ */
602
+ export enum ErrorCode {
603
+ LOCATION_PERMISSION_DENIED = "LOCATION_PERMISSION_DENIED",
604
+ BLUETOOTH_PERMISSION_DENIED = "BLUETOOTH_PERMISSION_DENIED",
605
+ BLUETOOTH_DISABLED = "BLUETOOTH_DISABLED",
606
+ LOCATION_DISABLED = "LOCATION_DISABLED",
607
+ REDUCED_ACCURACY = "REDUCED_ACCURACY",
608
+ UNKNOWN = "UNKNOWN",
609
+ }
610
+
611
+ /**
612
+ * @name Error
613
+ * @description Represents an error with a specific code, message, and type.
614
+ *
615
+ * @interface
616
+ * @property {ErrorCode} code - The specific error code associated with this error.
617
+ * @property {string} message - A descriptive message providing more details about the error.
618
+ * @property {ErrorType} type - The type of the error indicating its severity (critical or non-critical).
619
+ */
540
620
  export interface Error {
541
- code?: number;
621
+ code: ErrorCode;
542
622
  message: string;
623
+ type: ErrorType;
543
624
  }
544
625
 
545
626
  // TODO: add types
package/src/sdk/utils.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { logError } from "..";
2
2
  import type { Error } from "./types";
3
+ import { ErrorCode, ErrorType } from "./types";
3
4
 
4
5
  type PromiseResolve<T> = (response: T) => void;
5
6
  type PromiseReject = (error?: Error) => void;
@@ -23,8 +24,9 @@ export const handleAsyncCallback = (
23
24
  resolve();
24
25
  } else {
25
26
  reject({
26
- code: -1,
27
+ code: ErrorCode.UNKNOWN,
27
28
  message: errorMessage || "Unknown error.",
29
+ type: ErrorType.NON_CRITICAL,
28
30
  });
29
31
  }
30
32
  };
@@ -121,9 +123,47 @@ export const promiseWrapper = <T>(
121
123
  } catch (error) {
122
124
  logError(error);
123
125
  reject({
124
- code: error?.code || -1,
126
+ code: ErrorCode.UNKNOWN,
125
127
  message: error?.message || "Unknown error.",
128
+ type: ErrorType.NON_CRITICAL,
126
129
  });
127
130
  }
128
131
  });
129
132
  };
133
+
134
+ export function locationErrorAdapter(error): Error {
135
+ let adaptedCode = ErrorCode.UNKNOWN;
136
+ const adaptedMessage = error.message;
137
+ const adaptedType = ErrorType.CRITICAL;
138
+
139
+ switch (error.code.toString()) {
140
+ case "8001": // MISSING_LOCATION_PERMISSION
141
+ case "8": // kSITLocationErrorLocationDisabled
142
+ case "9": // kSITLocationErrorLocationRestricted
143
+ case "10": // kSITLocationErrorLocationAuthStatusNotDetermined
144
+ adaptedCode = ErrorCode.LOCATION_PERMISSION_DENIED;
145
+ break;
146
+ case "8002": // LOCATION_DISABLED
147
+ adaptedCode = ErrorCode.LOCATION_DISABLED;
148
+ break;
149
+ case "8012": // MISSING_BLUETOOTH_PERMISSION
150
+ adaptedCode = ErrorCode.BLUETOOTH_PERMISSION_DENIED;
151
+ break;
152
+ case "8100": //BLUETOOTH_DISABLED. 8100 ->This number does not exist in Situm SDK. We made it up in SitumMapper.java (RN adapter)
153
+ case "6": // kSITLocationErrorBluetoothisOff
154
+ adaptedCode = ErrorCode.BLUETOOTH_DISABLED;
155
+ break;
156
+ case "11": //kSITLocationErrorLocationAccuracyAuthorizationStatusReducedAccuracy
157
+ adaptedCode = ErrorCode.REDUCED_ACCURACY;
158
+ break;
159
+ // Add more cases as needed
160
+ }
161
+
162
+ const returnError: Error = {
163
+ code: adaptedCode,
164
+ message: adaptedMessage,
165
+ type: adaptedType,
166
+ };
167
+
168
+ return returnError;
169
+ }
@@ -8,7 +8,7 @@ import {
8
8
 
9
9
  // TODO: can requestMultiple be used ?
10
10
  const checkIOSPermissions = async () => {
11
- let granted = await request(PERMISSIONS.IOS.LOCATION_WHEN_IN_USE);
11
+ const granted = await request(PERMISSIONS.IOS.LOCATION_WHEN_IN_USE);
12
12
 
13
13
  // Check if already denied
14
14
  if (granted !== RESULTS.GRANTED) {
@@ -19,24 +19,7 @@ const checkIOSPermissions = async () => {
19
19
  "Situm > permissions > LOCATION_WHEN_IN_USE permission granted"
20
20
  );
21
21
 
22
- //@ts-ignore
23
- if (parseInt(Platform.Version, 10) > 12) {
24
- granted = await request(PERMISSIONS.IOS.BLUETOOTH_PERIPHERAL);
25
-
26
- if (granted === RESULTS.GRANTED) {
27
- console.debug(
28
- "Situm > permissions > BLUETOOTH_PERIPHERAL permission granted"
29
- );
30
- return true;
31
- } else {
32
- throw "Situm > permissions > BLUETOOTH_PERIPHERAL permission not granted";
33
- }
34
- } else {
35
- console.debug(
36
- "Situm > permissions > BLUETOOTH_PERIPHERAL permissions not required"
37
- );
38
- return true;
39
- }
22
+ return true;
40
23
  };
41
24
 
42
25
  const checkAndroidPermissions = async () => {
@@ -5,6 +5,8 @@ import SitumPlugin from "../../sdk";
5
5
  import {
6
6
  type Building,
7
7
  type Error,
8
+ ErrorCode,
9
+ ErrorType,
8
10
  type Location,
9
11
  type LocationStatus,
10
12
  type NavigationProgress,
@@ -77,8 +79,6 @@ export const useSitumInternal = () => {
77
79
 
78
80
  SitumPlugin.onLocationError((err: Error) => {
79
81
  console.error(`Situm > hook > Error while positioning: ${err}}`);
80
- //@ts-ignore
81
- dispatch(setError({ message: err, code: 3001 } as SDKError));
82
82
  });
83
83
 
84
84
  SitumPlugin.onLocationStopped(() => {
@@ -207,7 +207,14 @@ export const useSitumInternal = () => {
207
207
  });
208
208
  } catch (e) {
209
209
  console.error(`Situm > hook > Could not update navigation ${e}`);
210
- dispatch(setError({ message: "error", code: 3051 } as Error));
210
+ //TODO: Remove this and emit these errors in SitumPlugin.onNavigationError
211
+ dispatch(
212
+ setError({
213
+ message: "Could not update navigation",
214
+ code: ErrorCode.UNKNOWN,
215
+ type: ErrorType.NON_CRITICAL,
216
+ } as Error)
217
+ );
211
218
  stopNavigation();
212
219
  }
213
220
  })
@@ -219,11 +226,11 @@ export const useSitumInternal = () => {
219
226
  };
220
227
 
221
228
  const stopNavigation = () => {
222
- console.debug("Situm > hook > Stopping navigation");
223
229
  // TODO: we should delegate this to the sdk plugin
224
230
  if (!navigation || navigation?.status === NavigationStatus.STOP) {
225
231
  return;
226
232
  }
233
+ console.debug("Situm > hook > Stopping navigation");
227
234
 
228
235
  SitumPlugin.removeNavigationUpdates()
229
236
  .then(() => {