react-native-okhi 1.2.3-beta.7 → 1.2.3

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 (32) hide show
  1. package/android/build.gradle +1 -1
  2. package/android/src/main/java/com/reactnativeokhi/OkhiModule.java +0 -2
  3. package/ios/Okhi.m +0 -1
  4. package/ios/Okhi.swift +0 -24
  5. package/lib/commonjs/OkCollect/OkHiLocationManager.js +7 -104
  6. package/lib/commonjs/OkCollect/OkHiLocationManager.js.map +1 -1
  7. package/lib/commonjs/OkCollect/Util.js +25 -29
  8. package/lib/commonjs/OkCollect/Util.js.map +1 -1
  9. package/lib/commonjs/OkCollect/app.json +1 -1
  10. package/lib/commonjs/OkCollect/types.js.map +1 -1
  11. package/lib/commonjs/OkCore/types.js +0 -4
  12. package/lib/commonjs/OkCore/types.js.map +1 -1
  13. package/lib/commonjs/OkHiNativeModule/index.js.map +1 -1
  14. package/lib/module/OkCollect/OkHiLocationManager.js +8 -105
  15. package/lib/module/OkCollect/OkHiLocationManager.js.map +1 -1
  16. package/lib/module/OkCollect/Util.js +25 -29
  17. package/lib/module/OkCollect/Util.js.map +1 -1
  18. package/lib/module/OkCollect/app.json +1 -1
  19. package/lib/module/OkCollect/types.js.map +1 -1
  20. package/lib/module/OkCore/types.js +1 -1
  21. package/lib/module/OkCore/types.js.map +1 -1
  22. package/lib/module/OkHiNativeModule/index.js.map +1 -1
  23. package/lib/typescript/OkCollect/types.d.ts +5 -3
  24. package/lib/typescript/OkCore/types.d.ts +1 -2
  25. package/lib/typescript/OkHiNativeModule/index.d.ts +0 -2
  26. package/package.json +1 -1
  27. package/src/OkCollect/OkHiLocationManager.tsx +5 -132
  28. package/src/OkCollect/Util.ts +29 -37
  29. package/src/OkCollect/app.json +1 -1
  30. package/src/OkCollect/types.ts +2 -4
  31. package/src/OkCore/types.ts +1 -3
  32. package/src/OkHiNativeModule/index.ts +1 -6
@@ -20,13 +20,7 @@ import { start as sv } from '../OkVerify';
20
20
  import type { OkVerifyStartConfiguration } from '../OkVerify/types';
21
21
  import {
22
22
  getApplicationConfiguration,
23
- isBackgroundLocationPermissionGranted,
24
- isLocationPermissionGranted,
25
- isLocationServicesEnabled,
26
- openAppSettings,
27
23
  openProtectedAppsSettings,
28
- requestBackgroundLocationPermission,
29
- requestLocationPermission,
30
24
  } from '../OkCore';
31
25
  import { OkHiNativeModule } from '../OkHiNativeModule';
32
26
 
@@ -44,12 +38,10 @@ export const OkHiLocationManager = (props: OkHiLocationManagerProps) => {
44
38
  ? { ...props.style, ...defaultStyle }
45
39
  : defaultStyle;
46
40
 
47
- const { user, onSuccess, onCloseRequest, onError, loader, launch, config } =
48
- props;
41
+ const { user, onSuccess, onCloseRequest, onError, loader, launch } = props;
49
42
  const webViewRef = useRef<WebView | null>(null);
50
43
  const startMessage =
51
44
  props.mode === 'create' ? 'start_app' : 'select_location';
52
- const [ready, setReady] = useState(false);
53
45
 
54
46
  useEffect(() => {
55
47
  if (applicationConfiguration == null && token == null && user.phone) {
@@ -100,136 +92,21 @@ export const OkHiLocationManager = (props: OkHiLocationManagerProps) => {
100
92
  }
101
93
  }, [applicationConfiguration, props, token]);
102
94
 
103
- useEffect(() => {
104
- if (launch) {
105
- if (
106
- typeof config?.permissionsOnboarding === 'boolean' &&
107
- !config.permissionsOnboarding
108
- ) {
109
- isBackgroundLocationPermissionGranted().then((result) => {
110
- if (!result) {
111
- onError(
112
- new OkHiException({
113
- code: OkHiException.PERMISSION_DENIED_CODE,
114
- message:
115
- 'Always location permission must be granted to launch OkCollect',
116
- })
117
- );
118
- } else {
119
- setReady(true);
120
- }
121
- });
122
- } else {
123
- setReady(true);
124
- }
125
- } else {
126
- setReady(false);
127
- }
128
- }, [launch, config?.permissionsOnboarding]);
129
-
130
- const runWebViewCallback = (value: string) => {
131
- if (webViewRef.current) {
132
- const jsString = `(function (){ if (typeof runOkHiLocationManagerCallback === "function") { runOkHiLocationManagerCallback("${value}") } })()`;
133
- webViewRef.current.injectJavaScript(jsString);
134
- }
135
- };
136
-
137
- const handleAndroidRequestLocationPermission = async (
138
- level: 'whenInUse' | 'always'
139
- ) => {
140
- if (level === 'whenInUse') {
141
- const result = await requestLocationPermission();
142
- runWebViewCallback(result ? 'whenInUse' : 'denied');
143
- } else if (level === 'always') {
144
- const result = await requestBackgroundLocationPermission();
145
- if (result) {
146
- runWebViewCallback('always');
147
- } else {
148
- const isWhenInUseGranted = await isLocationPermissionGranted();
149
- runWebViewCallback(isWhenInUseGranted ? 'whenInUse' : 'denied');
150
- }
151
- }
152
- };
153
-
154
- const handleIOSRequestLocationPermission = async (
155
- level: 'whenInUse' | 'always'
156
- ) => {
157
- const serviceError = new OkHiException({
158
- code: OkHiException.SERVICE_UNAVAILABLE_CODE,
159
- message:
160
- 'Location service is currently not available. Please enable in app settings',
161
- });
162
- const unknownError = new OkHiException({
163
- code: OkHiException.UNKNOWN_ERROR_CODE,
164
- message:
165
- 'Something went wrong while requesting permissions. Please try again later.',
166
- });
167
- try {
168
- const isServiceAvailable = await isLocationServicesEnabled();
169
- if (!isServiceAvailable) {
170
- onError(serviceError);
171
- } else if (level === 'whenInUse') {
172
- const result = await requestLocationPermission();
173
- runWebViewCallback(result ? level : 'denied');
174
- } else if (level === 'always') {
175
- const granted = await isBackgroundLocationPermissionGranted();
176
- if (granted) {
177
- runWebViewCallback(level);
178
- } else {
179
- openAppSettings();
180
- }
181
- }
182
- } catch (error) {
183
- onError(unknownError);
184
- }
185
- };
186
-
187
- const handleRequestLocationPermission = async ({
188
- level,
189
- }: {
190
- level: 'whenInUse' | 'always';
191
- }) => {
192
- if (Platform.OS === 'android') {
193
- handleAndroidRequestLocationPermission(level);
194
- } else if (Platform.OS === 'ios') {
195
- handleIOSRequestLocationPermission(level);
196
- }
197
- };
198
-
199
- const handleOpenAppSettings = async () => {
200
- try {
201
- const granted = await isBackgroundLocationPermissionGranted();
202
- if (granted) {
203
- runWebViewCallback('always');
204
- } else {
205
- await openAppSettings();
206
- }
207
- } catch (error) {
208
- const err = error as OkHiException;
209
- onError(err);
210
- }
211
- };
212
-
213
95
  const handleOnMessage = ({ nativeEvent: { data } }: WebViewMessageEvent) => {
214
96
  try {
215
97
  const response: OkHiLocationManagerResponse = JSON.parse(data);
216
-
217
98
  if (response.message === 'fatal_exit') {
218
99
  onError(
219
100
  new OkHiException({
220
101
  code: OkHiException.UNKNOWN_ERROR_CODE,
221
- message: 'Something went wrong, please try again later.',
102
+ message: response.payload.toString(),
222
103
  })
223
104
  );
224
105
  } else if (response.message === 'exit_app') {
225
106
  onCloseRequest();
226
107
  } else if (response.message === 'request_enable_protected_apps') {
227
108
  openProtectedAppsSettings();
228
- } else if (
229
- response.message === 'location_created' ||
230
- response.message === 'location_selected' ||
231
- response.message === 'location_updated'
232
- ) {
109
+ } else {
233
110
  onSuccess({
234
111
  user: {
235
112
  ...response.payload.user,
@@ -262,10 +139,6 @@ export const OkHiLocationManager = (props: OkHiLocationManagerProps) => {
262
139
  });
263
140
  },
264
141
  });
265
- } else if (response.message === 'request_location_permission') {
266
- handleRequestLocationPermission(response.payload);
267
- } else if (response.message === 'open_app_settings') {
268
- handleOpenAppSettings();
269
142
  }
270
143
  } catch (error) {
271
144
  let errorMessage = 'Something went wrong';
@@ -331,10 +204,10 @@ export const OkHiLocationManager = (props: OkHiLocationManagerProps) => {
331
204
  <Modal
332
205
  animationType="slide"
333
206
  transparent={false}
334
- visible={ready}
207
+ visible={launch}
335
208
  onRequestClose={handleModalRequestClose}
336
209
  >
337
- {ready ? renderContent() : null}
210
+ {launch ? renderContent() : null}
338
211
  </Modal>
339
212
  );
340
213
  };
@@ -34,8 +34,6 @@ export const generateStartDataPayload = async (
34
34
  applicationConfiguration: AuthApplicationConfig
35
35
  ): Promise<OkHiLocationManagerStartDataPayload> => {
36
36
  const payload: any = {};
37
- const { manufacturer, model, osVersion, platform } =
38
- await OkHiNativeModule.retrieveDeviceInfo();
39
37
  payload.style = !props.theme
40
38
  ? undefined
41
39
  : {
@@ -69,12 +67,6 @@ export const generateStartDataPayload = async (
69
67
  platform: {
70
68
  name: 'react-native',
71
69
  },
72
- device: {
73
- manufacturer,
74
- model,
75
- platform,
76
- osVersion,
77
- },
78
70
  };
79
71
  payload.config = {
80
72
  streetView:
@@ -97,39 +89,34 @@ export const generateStartDataPayload = async (
97
89
  },
98
90
  protectedApps:
99
91
  Platform.OS === 'android' && (await canOpenProtectedAppsSettings()),
100
- permissionsOnboarding:
101
- typeof props.config?.permissionsOnboarding === 'boolean'
102
- ? props.config.permissionsOnboarding
103
- : true,
104
92
  };
105
93
 
106
94
  if (Platform.OS === 'ios') {
107
95
  const status = await OkHiNativeModule.fetchIOSLocationPermissionStatus();
108
- const locationPermission =
109
- status === 'notDetermined'
110
- ? 'notDetermined'
111
- : status === 'authorizedWhenInUse'
112
- ? 'whenInUse'
113
- : status === 'authorizedAlways'
114
- ? 'always'
115
- : 'denied';
116
- payload.context.permissions = {
117
- location: locationPermission,
118
- };
119
- if (
120
- status === 'authorized' ||
121
- status === 'authorizedWhenInUse' ||
122
- status === 'authorizedAlways'
123
- ) {
124
- const location = await fetchCurrentLocation();
125
- if (location) {
126
- payload.context.coordinates = {
127
- currentLocation: {
128
- lat: location.lat,
129
- lng: location.lng,
130
- accuracy: location.accuracy,
131
- },
132
- };
96
+ if (status !== 'notDetermined') {
97
+ payload.context.permissions = {
98
+ location:
99
+ status === 'authorizedWhenInUse'
100
+ ? 'whenInUse'
101
+ : status === 'authorizedAlways' || status === 'authorized'
102
+ ? 'always'
103
+ : 'denided',
104
+ };
105
+ if (
106
+ status === 'authorized' ||
107
+ status === 'authorizedWhenInUse' ||
108
+ status === 'authorizedAlways'
109
+ ) {
110
+ const location = await fetchCurrentLocation();
111
+ if (location) {
112
+ payload.context.coordinates = {
113
+ currentLocation: {
114
+ lat: location.lat,
115
+ lng: location.lng,
116
+ accuracy: location.accuracy,
117
+ },
118
+ };
119
+ }
133
120
  }
134
121
  }
135
122
  } else if (Platform.OS === 'android') {
@@ -160,6 +147,11 @@ export const generateStartDataPayload = async (
160
147
  : 'denied',
161
148
  };
162
149
  }
150
+ const { manufacturer, model } = await OkHiNativeModule.retrieveDeviceInfo();
151
+ payload.context.device = {
152
+ manufacturer,
153
+ model,
154
+ };
163
155
  } else {
164
156
  throw new OkHiException({
165
157
  code: OkHiException.UNSUPPORTED_PLATFORM_CODE,
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "okhiWebReactNative",
3
- "version": "1.2.3-beta.7"
3
+ "version": "1.2.3"
4
4
  }
@@ -79,7 +79,6 @@ export interface OkHiLocationManagerProps {
79
79
  home?: boolean;
80
80
  work?: boolean;
81
81
  };
82
- permissionsOnboarding?: boolean;
83
82
  };
84
83
 
85
84
  /**
@@ -143,7 +142,6 @@ export interface OkHiLocationManagerResponse {
143
142
  | 'location_updated'
144
143
  | 'exit_app'
145
144
  | 'request_enable_protected_apps'
146
- | 'fatal_exit'
147
- | 'request_location_permission';
148
- payload: any;
145
+ | 'fatal_exit';
146
+ payload: { user: any; location: any };
149
147
  }
@@ -1,5 +1,3 @@
1
- import type { OkHiException } from './OkHiException';
2
-
3
1
  /**
4
2
  * Defines the structure of the user object requried by OkHi services and libraries.
5
3
  */
@@ -211,5 +209,5 @@ export type LocationRequestPermissionType = 'whenInUse' | 'always';
211
209
 
212
210
  export type LocationPermissionCallback = (
213
211
  status: LocationPermissionStatusCallback | null,
214
- error: OkHiException | null
212
+ error: OkHiError | null
215
213
  ) => any;
@@ -44,12 +44,7 @@ type OkHiNativeModuleType = {
44
44
  requestTrackingAuthorization(): Promise<string | null>;
45
45
  canOpenProtectedAppsSettings(): Promise<boolean>;
46
46
  openProtectedAppsSettings(): Promise<boolean>;
47
- retrieveDeviceInfo(): Promise<{
48
- manufacturer: string;
49
- model: string;
50
- osVersion: string;
51
- platform: 'android' | 'ios';
52
- }>;
47
+ retrieveDeviceInfo(): Promise<{ manufacturer: string; model: string }>;
53
48
  setItem(key: string, value: string): Promise<boolean>;
54
49
  onNewToken(fcmPushNotificationToken: string): Promise<boolean>;
55
50
  onMessageReceived(): Promise<boolean>;