react-native-okhi 1.2.31 → 1.2.32-beta.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.
- package/LICENSE +1 -1
- package/README.md +34 -4
- package/ReactNativeOkhi.podspec +21 -0
- package/android/build.gradle +38 -99
- package/android/gradle.properties +3 -3
- package/android/src/main/AndroidManifest.xml +1 -3
- package/android/src/main/java/com/okhi/OkhiModule.kt +336 -0
- package/android/src/main/java/com/okhi/OkhiPackage.kt +33 -0
- package/ios/OkHiWrapper.swift +348 -0
- package/ios/Okhi.h +5 -0
- package/ios/Okhi.mm +170 -0
- package/lib/commonjs/NativeOkhi.js +9 -0
- package/lib/commonjs/NativeOkhi.js.map +1 -0
- package/lib/commonjs/index.js +234 -28
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/module/NativeOkhi.js +5 -0
- package/lib/module/NativeOkhi.js.map +1 -0
- package/lib/module/index.js +221 -3
- package/lib/module/index.js.map +1 -1
- package/lib/module/package.json +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/src/NativeOkhi.d.ts +25 -0
- package/lib/typescript/commonjs/src/NativeOkhi.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/index.d.ts +22 -0
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/types.d.ts +81 -0
- package/lib/typescript/commonjs/src/types.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/src/NativeOkhi.d.ts +25 -0
- package/lib/typescript/module/src/NativeOkhi.d.ts.map +1 -0
- package/lib/typescript/module/src/index.d.ts +22 -0
- package/lib/typescript/module/src/index.d.ts.map +1 -0
- package/lib/typescript/module/src/types.d.ts +81 -0
- package/lib/typescript/module/src/types.d.ts.map +1 -0
- package/package.json +91 -112
- package/src/NativeOkhi.ts +68 -0
- package/src/index.tsx +271 -3
- package/src/types.ts +90 -0
- package/android/src/main/java/com/reactnativeokhi/OkhiModule.java +0 -389
- package/android/src/main/java/com/reactnativeokhi/OkhiPackage.java +0 -28
- package/ios/OkHiExtension.swift +0 -27
- package/ios/OkHiStruct.swift +0 -29
- package/ios/Okhi-Bridging-Header.h +0 -3
- package/ios/Okhi.m +0 -62
- package/ios/Okhi.swift +0 -325
- package/ios/Okhi.xcodeproj/project.pbxproj +0 -283
- package/lib/commonjs/OkCollect/Helpers.js +0 -40
- package/lib/commonjs/OkCollect/Helpers.js.map +0 -1
- package/lib/commonjs/OkCollect/OkHiLocationManager.js +0 -305
- package/lib/commonjs/OkCollect/OkHiLocationManager.js.map +0 -1
- package/lib/commonjs/OkCollect/Spinner.js +0 -27
- package/lib/commonjs/OkCollect/Spinner.js.map +0 -1
- package/lib/commonjs/OkCollect/Util.js +0 -226
- package/lib/commonjs/OkCollect/Util.js.map +0 -1
- package/lib/commonjs/OkCollect/app.json +0 -4
- package/lib/commonjs/OkCollect/index.js +0 -47
- package/lib/commonjs/OkCollect/index.js.map +0 -1
- package/lib/commonjs/OkCollect/types.js +0 -6
- package/lib/commonjs/OkCollect/types.js.map +0 -1
- package/lib/commonjs/OkCore/Helpers.js +0 -386
- package/lib/commonjs/OkCore/Helpers.js.map +0 -1
- package/lib/commonjs/OkCore/OkHiException.js +0 -96
- package/lib/commonjs/OkCore/OkHiException.js.map +0 -1
- package/lib/commonjs/OkCore/OkHiMode.js +0 -14
- package/lib/commonjs/OkCore/OkHiMode.js.map +0 -1
- package/lib/commonjs/OkCore/_helpers.js +0 -41
- package/lib/commonjs/OkCore/_helpers.js.map +0 -1
- package/lib/commonjs/OkCore/_types.js +0 -2
- package/lib/commonjs/OkCore/_types.js.map +0 -1
- package/lib/commonjs/OkCore/index.js +0 -119
- package/lib/commonjs/OkCore/index.js.map +0 -1
- package/lib/commonjs/OkCore/types.js +0 -6
- package/lib/commonjs/OkCore/types.js.map +0 -1
- package/lib/commonjs/OkHiNativeModule/index.js +0 -19
- package/lib/commonjs/OkHiNativeModule/index.js.map +0 -1
- package/lib/commonjs/OkVerify/index.js +0 -211
- package/lib/commonjs/OkVerify/index.js.map +0 -1
- package/lib/commonjs/OkVerify/types.js.map +0 -1
- package/lib/module/OkCollect/Helpers.js +0 -34
- package/lib/module/OkCollect/Helpers.js.map +0 -1
- package/lib/module/OkCollect/OkHiLocationManager.js +0 -298
- package/lib/module/OkCollect/OkHiLocationManager.js.map +0 -1
- package/lib/module/OkCollect/Spinner.js +0 -20
- package/lib/module/OkCollect/Spinner.js.map +0 -1
- package/lib/module/OkCollect/Util.js +0 -214
- package/lib/module/OkCollect/Util.js.map +0 -1
- package/lib/module/OkCollect/app.json +0 -4
- package/lib/module/OkCollect/index.js +0 -4
- package/lib/module/OkCollect/index.js.map +0 -1
- package/lib/module/OkCollect/types.js +0 -2
- package/lib/module/OkCollect/types.js.map +0 -1
- package/lib/module/OkCore/Helpers.js +0 -363
- package/lib/module/OkCore/Helpers.js.map +0 -1
- package/lib/module/OkCore/OkHiException.js +0 -89
- package/lib/module/OkCore/OkHiException.js.map +0 -1
- package/lib/module/OkCore/OkHiMode.js +0 -8
- package/lib/module/OkCore/OkHiMode.js.map +0 -1
- package/lib/module/OkCore/_helpers.js +0 -34
- package/lib/module/OkCore/_helpers.js.map +0 -1
- package/lib/module/OkCore/_types.js +0 -2
- package/lib/module/OkCore/_types.js.map +0 -1
- package/lib/module/OkCore/index.js +0 -65
- package/lib/module/OkCore/index.js.map +0 -1
- package/lib/module/OkCore/types.js +0 -2
- package/lib/module/OkCore/types.js.map +0 -1
- package/lib/module/OkHiNativeModule/index.js +0 -13
- package/lib/module/OkHiNativeModule/index.js.map +0 -1
- package/lib/module/OkVerify/index.js +0 -195
- package/lib/module/OkVerify/index.js.map +0 -1
- package/lib/module/OkVerify/types.js +0 -2
- package/lib/module/OkVerify/types.js.map +0 -1
- package/lib/typescript/OkCollect/Helpers.d.ts +0 -9
- package/lib/typescript/OkCollect/OkHiLocationManager.d.ts +0 -7
- package/lib/typescript/OkCollect/Spinner.d.ts +0 -5
- package/lib/typescript/OkCollect/Util.d.ts +0 -31
- package/lib/typescript/OkCollect/index.d.ts +0 -3
- package/lib/typescript/OkCollect/types.d.ts +0 -139
- package/lib/typescript/OkCore/Helpers.d.ts +0 -95
- package/lib/typescript/OkCore/OkHiException.d.ts +0 -81
- package/lib/typescript/OkCore/OkHiMode.d.ts +0 -7
- package/lib/typescript/OkCore/_helpers.d.ts +0 -3
- package/lib/typescript/OkCore/_types.d.ts +0 -38
- package/lib/typescript/OkCore/index.d.ts +0 -17
- package/lib/typescript/OkCore/types.d.ts +0 -203
- package/lib/typescript/OkHiNativeModule/index.d.ts +0 -48
- package/lib/typescript/OkVerify/index.d.ts +0 -65
- package/lib/typescript/OkVerify/types.d.ts +0 -0
- package/lib/typescript/index.d.ts +0 -3
- package/react-native-okhi.podspec +0 -35
- package/src/OkCollect/Helpers.ts +0 -53
- package/src/OkCollect/OkHiLocationManager.tsx +0 -391
- package/src/OkCollect/Spinner.tsx +0 -18
- package/src/OkCollect/Util.ts +0 -270
- package/src/OkCollect/app.json +0 -4
- package/src/OkCollect/index.ts +0 -3
- package/src/OkCollect/types.ts +0 -154
- package/src/OkCore/Helpers.ts +0 -477
- package/src/OkCore/OkHiException.ts +0 -93
- package/src/OkCore/OkHiMode.ts +0 -7
- package/src/OkCore/_helpers.ts +0 -47
- package/src/OkCore/_types.ts +0 -37
- package/src/OkCore/index.ts +0 -87
- package/src/OkCore/types.ts +0 -235
- package/src/OkHiNativeModule/index.ts +0 -92
- package/src/OkVerify/index.ts +0 -259
- package/src/OkVerify/types.ts +0 -0
- /package/lib/commonjs/{OkVerify/types.js → types.js} +0 -0
|
@@ -1,391 +0,0 @@
|
|
|
1
|
-
import React, { useState, useEffect, useRef } from 'react';
|
|
2
|
-
import { Modal, SafeAreaView, Platform } from 'react-native';
|
|
3
|
-
import { WebView, WebViewMessageEvent } from 'react-native-webview';
|
|
4
|
-
import { Spinner } from './Spinner';
|
|
5
|
-
import type {
|
|
6
|
-
OkHiLocationManagerResponse,
|
|
7
|
-
OkHiLocationManagerProps,
|
|
8
|
-
OkHiLocationManagerStartDataPayload,
|
|
9
|
-
} from './types';
|
|
10
|
-
import {
|
|
11
|
-
getFrameUrl,
|
|
12
|
-
generateJavaScriptStartScript,
|
|
13
|
-
generateStartDataPayload,
|
|
14
|
-
parseOkHiLocation,
|
|
15
|
-
fetchCurrentLocation,
|
|
16
|
-
} from './Util';
|
|
17
|
-
import { OkHiException } from '../OkCore/OkHiException';
|
|
18
|
-
import type { AuthApplicationConfig } from '../OkCore/_types';
|
|
19
|
-
import { start as sv } from '../OkVerify';
|
|
20
|
-
import {
|
|
21
|
-
getApplicationConfiguration,
|
|
22
|
-
isBackgroundLocationPermissionGranted,
|
|
23
|
-
isLocationPermissionGranted,
|
|
24
|
-
openAppSettings,
|
|
25
|
-
openProtectedAppsSettings,
|
|
26
|
-
requestBackgroundLocationPermission,
|
|
27
|
-
requestLocationPermission,
|
|
28
|
-
UsageType,
|
|
29
|
-
} from '../OkCore';
|
|
30
|
-
import { OkHiNativeModule } from '../OkHiNativeModule';
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* The OkHiLocationManager React Component is used to display an in app modal, enabling the user to quickly create an accurate OkHi address.
|
|
34
|
-
*/
|
|
35
|
-
export const OkHiLocationManager = (props: OkHiLocationManagerProps) => {
|
|
36
|
-
const [applicationConfiguration, setApplicationConfiguration] =
|
|
37
|
-
useState<AuthApplicationConfig | null>(null);
|
|
38
|
-
const [startPayload, setStartPaylaod] =
|
|
39
|
-
useState<null | OkHiLocationManagerStartDataPayload>(null);
|
|
40
|
-
const defaultStyle = { flex: 1 };
|
|
41
|
-
const style = props.style
|
|
42
|
-
? { ...props.style, ...defaultStyle }
|
|
43
|
-
: defaultStyle;
|
|
44
|
-
|
|
45
|
-
const { user, onSuccess, onCloseRequest, onError, loader, launch } = props;
|
|
46
|
-
const webViewRef = useRef<WebView | null>(null);
|
|
47
|
-
const startMessage =
|
|
48
|
-
props.mode === 'create' ? 'start_app' : 'select_location';
|
|
49
|
-
const [ready, setReady] = useState(false);
|
|
50
|
-
const androidAlwaysRequested = useRef(false);
|
|
51
|
-
|
|
52
|
-
useEffect(() => {
|
|
53
|
-
if (typeof launch === 'boolean') {
|
|
54
|
-
setReady(launch);
|
|
55
|
-
}
|
|
56
|
-
}, [launch]);
|
|
57
|
-
|
|
58
|
-
useEffect(() => {
|
|
59
|
-
async function startOkHiLocationManager() {
|
|
60
|
-
const appConfiguration = await getApplicationConfiguration();
|
|
61
|
-
if (!appConfiguration) {
|
|
62
|
-
throw new OkHiException({
|
|
63
|
-
code: OkHiException.UNAUTHORIZED_CODE,
|
|
64
|
-
message: OkHiException.UNAUTHORIZED_MESSAGE,
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
const startPayload = await generateStartDataPayload(
|
|
68
|
-
props,
|
|
69
|
-
appConfiguration
|
|
70
|
-
);
|
|
71
|
-
setApplicationConfiguration(appConfiguration);
|
|
72
|
-
setStartPaylaod(startPayload);
|
|
73
|
-
if (Platform.OS === 'android' && Platform.Version > 25) {
|
|
74
|
-
OkHiNativeModule.setItem(
|
|
75
|
-
'okcollect-launch-payload',
|
|
76
|
-
JSON.stringify({
|
|
77
|
-
message: startMessage,
|
|
78
|
-
payload: startPayload,
|
|
79
|
-
url: getFrameUrl(appConfiguration),
|
|
80
|
-
})
|
|
81
|
-
).catch(console.error);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (launch) {
|
|
86
|
-
startOkHiLocationManager();
|
|
87
|
-
}
|
|
88
|
-
}, [launch, props, onError]);
|
|
89
|
-
|
|
90
|
-
const runWebViewCallback = async (result: string) => {
|
|
91
|
-
const level = await OkHiNativeModule.getLocationAccuracyLevel();
|
|
92
|
-
let callbackResult = result;
|
|
93
|
-
if (
|
|
94
|
-
(result === 'blocked' || result === 'denied') &&
|
|
95
|
-
level === 'approximate'
|
|
96
|
-
) {
|
|
97
|
-
callbackResult = 'whenInUse';
|
|
98
|
-
}
|
|
99
|
-
const update = { locationAccuracyLevel: level };
|
|
100
|
-
const jsonUpdate = JSON.stringify(update)
|
|
101
|
-
.replace(/\\/g, '\\\\')
|
|
102
|
-
.replace(/"/g, '\\"');
|
|
103
|
-
const jsString = `
|
|
104
|
-
(function (){
|
|
105
|
-
if (typeof runOkHiLocationManagerCallback === "function") {
|
|
106
|
-
runOkHiLocationManagerCallback("${callbackResult}", "${jsonUpdate}")
|
|
107
|
-
}
|
|
108
|
-
})()
|
|
109
|
-
`;
|
|
110
|
-
webViewRef.current?.injectJavaScript(jsString);
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
const handleAndroidRequestLocationPermission = async (
|
|
114
|
-
level: 'whenInUse' | 'always'
|
|
115
|
-
) => {
|
|
116
|
-
try {
|
|
117
|
-
const _isLocationPermissionGranted = await isLocationPermissionGranted();
|
|
118
|
-
const _isBackgroundLocationPermissionGranted =
|
|
119
|
-
await isBackgroundLocationPermissionGranted();
|
|
120
|
-
const _locationAccuracyLevel =
|
|
121
|
-
await OkHiNativeModule.getLocationAccuracyLevel();
|
|
122
|
-
if (
|
|
123
|
-
_isBackgroundLocationPermissionGranted &&
|
|
124
|
-
_locationAccuracyLevel === 'precise'
|
|
125
|
-
) {
|
|
126
|
-
runWebViewCallback('always');
|
|
127
|
-
} else if (
|
|
128
|
-
level === 'whenInUse' &&
|
|
129
|
-
_isLocationPermissionGranted &&
|
|
130
|
-
_locationAccuracyLevel === 'precise'
|
|
131
|
-
) {
|
|
132
|
-
runWebViewCallback('whenInUse');
|
|
133
|
-
} else if (
|
|
134
|
-
level === 'whenInUse' &&
|
|
135
|
-
_locationAccuracyLevel === 'no_permission'
|
|
136
|
-
) {
|
|
137
|
-
const result = await requestLocationPermission();
|
|
138
|
-
runWebViewCallback(result ? 'whenInUse' : 'denied');
|
|
139
|
-
} else if (level === 'always') {
|
|
140
|
-
const result = await requestBackgroundLocationPermission();
|
|
141
|
-
runWebViewCallback(result ? 'always' : 'denied');
|
|
142
|
-
androidAlwaysRequested.current = true;
|
|
143
|
-
} else if (
|
|
144
|
-
level === 'whenInUse' &&
|
|
145
|
-
_locationAccuracyLevel === 'approximate'
|
|
146
|
-
) {
|
|
147
|
-
const result = await requestLocationPermission();
|
|
148
|
-
runWebViewCallback(result ? 'whenInUse' : 'denied');
|
|
149
|
-
} else {
|
|
150
|
-
openAppSettings();
|
|
151
|
-
}
|
|
152
|
-
} catch (error) {
|
|
153
|
-
onError(
|
|
154
|
-
new OkHiException({
|
|
155
|
-
code: 'unknown',
|
|
156
|
-
message: 'could not request permission',
|
|
157
|
-
})
|
|
158
|
-
);
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
const handleIOSRequestLocationPermission = async (level: string) => {
|
|
163
|
-
try {
|
|
164
|
-
const _isLocationPermissionGranted = await isLocationPermissionGranted();
|
|
165
|
-
const _isBackgroundLocationPermissionGranted =
|
|
166
|
-
await isBackgroundLocationPermissionGranted();
|
|
167
|
-
const _locationAccuracyLevel =
|
|
168
|
-
await OkHiNativeModule.getLocationAccuracyLevel();
|
|
169
|
-
|
|
170
|
-
if (
|
|
171
|
-
_isBackgroundLocationPermissionGranted &&
|
|
172
|
-
_locationAccuracyLevel === 'precise'
|
|
173
|
-
) {
|
|
174
|
-
runWebViewCallback('always');
|
|
175
|
-
} else if (
|
|
176
|
-
level === 'whenInUse' &&
|
|
177
|
-
_isLocationPermissionGranted &&
|
|
178
|
-
_locationAccuracyLevel === 'precise'
|
|
179
|
-
) {
|
|
180
|
-
runWebViewCallback('whenInUse');
|
|
181
|
-
} else if (level === 'whenInUse' && !_isLocationPermissionGranted) {
|
|
182
|
-
const result = await requestLocationPermission();
|
|
183
|
-
runWebViewCallback(result ? 'whenInUse' : 'denied');
|
|
184
|
-
} else {
|
|
185
|
-
openAppSettings();
|
|
186
|
-
}
|
|
187
|
-
} catch (error) {
|
|
188
|
-
onError(
|
|
189
|
-
new OkHiException({
|
|
190
|
-
code: 'unknown',
|
|
191
|
-
message: 'could not request permission',
|
|
192
|
-
})
|
|
193
|
-
);
|
|
194
|
-
}
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
const handleRequestLocationPermission = async ({
|
|
198
|
-
level,
|
|
199
|
-
}: {
|
|
200
|
-
level: 'whenInUse' | 'always';
|
|
201
|
-
}) => {
|
|
202
|
-
if (Platform.OS === 'android') {
|
|
203
|
-
handleAndroidRequestLocationPermission(level);
|
|
204
|
-
} else if (Platform.OS === 'ios') {
|
|
205
|
-
handleIOSRequestLocationPermission(level);
|
|
206
|
-
}
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
const handleOpenAppSettings = async () => {
|
|
210
|
-
try {
|
|
211
|
-
const granted = await isBackgroundLocationPermissionGranted();
|
|
212
|
-
if (granted) {
|
|
213
|
-
runWebViewCallback('always');
|
|
214
|
-
} else {
|
|
215
|
-
await openAppSettings();
|
|
216
|
-
}
|
|
217
|
-
} catch (error) {
|
|
218
|
-
const err = error as OkHiException;
|
|
219
|
-
onError(err);
|
|
220
|
-
}
|
|
221
|
-
};
|
|
222
|
-
|
|
223
|
-
const handleFetchCurrentLocation = async () => {
|
|
224
|
-
try {
|
|
225
|
-
const location = await fetchCurrentLocation();
|
|
226
|
-
if (location) {
|
|
227
|
-
const jsString = `window.receiveCurrentLocation({lat: ${location.lat},lng: ${location.lng},accuracy: ${location.accuracy}})`;
|
|
228
|
-
webViewRef.current?.injectJavaScript(jsString);
|
|
229
|
-
}
|
|
230
|
-
} catch (error) {
|
|
231
|
-
console.error(error);
|
|
232
|
-
}
|
|
233
|
-
};
|
|
234
|
-
|
|
235
|
-
// prevents ios https... is requesting for your location
|
|
236
|
-
const handleWebViewOnLoad = () => {
|
|
237
|
-
if (Platform.OS === 'ios') {
|
|
238
|
-
const jsString =
|
|
239
|
-
'(function(){navigator.geolocation.watchPosition=navigator.geolocation.getCurrentPosition=function(s,e,o){if(window.ReactNativeWebView&&typeof window.ReactNativeWebView.postMessage==="function"){window.ReactNativeWebView.postMessage(JSON.stringify({message:"fetch_current_location",payload:{}}));}window.receiveCurrentLocation=function(l){s({coords:{latitude:l.lat,longitude:l.lng,accuracy:l.accuracy,altitude:null,altitudeAccuracy:null,heading:null,speed:null},timestamp:Date.now()});};};})();';
|
|
240
|
-
webViewRef.current?.injectJavaScript(jsString);
|
|
241
|
-
}
|
|
242
|
-
};
|
|
243
|
-
|
|
244
|
-
const handleOnMessage = ({ nativeEvent: { data } }: WebViewMessageEvent) => {
|
|
245
|
-
try {
|
|
246
|
-
const response: OkHiLocationManagerResponse = JSON.parse(data);
|
|
247
|
-
if (response.message === 'fatal_exit') {
|
|
248
|
-
//TODO: figure out bad phone number code
|
|
249
|
-
onError(
|
|
250
|
-
new OkHiException({
|
|
251
|
-
code: OkHiException.UNKNOWN_ERROR_CODE,
|
|
252
|
-
message: response.payload,
|
|
253
|
-
})
|
|
254
|
-
);
|
|
255
|
-
} else if (response.message === 'exit_app') {
|
|
256
|
-
onCloseRequest();
|
|
257
|
-
} else if (response.message === 'request_enable_protected_apps') {
|
|
258
|
-
openProtectedAppsSettings();
|
|
259
|
-
} else if (
|
|
260
|
-
response.message === 'location_created' ||
|
|
261
|
-
response.message === 'location_selected' ||
|
|
262
|
-
response.message === 'location_updated'
|
|
263
|
-
) {
|
|
264
|
-
setReady(false); // auto close
|
|
265
|
-
onSuccess({
|
|
266
|
-
user: {
|
|
267
|
-
...response.payload.user,
|
|
268
|
-
fcmPushNotificationToken: user.fcmPushNotificationToken,
|
|
269
|
-
},
|
|
270
|
-
location: parseOkHiLocation(response.payload.location),
|
|
271
|
-
startVerification: function () {
|
|
272
|
-
const createdUser = { ...this.user };
|
|
273
|
-
const location = { ...this.location };
|
|
274
|
-
return new Promise((resolve, reject) => {
|
|
275
|
-
if (!location.id) {
|
|
276
|
-
reject(
|
|
277
|
-
new OkHiException({
|
|
278
|
-
code: OkHiException.BAD_REQUEST_CODE,
|
|
279
|
-
message: 'Missing location id from response',
|
|
280
|
-
})
|
|
281
|
-
);
|
|
282
|
-
} else if (!createdUser.id) {
|
|
283
|
-
reject(
|
|
284
|
-
new OkHiException({
|
|
285
|
-
code: OkHiException.BAD_REQUEST_CODE,
|
|
286
|
-
message: 'Missing user id from response',
|
|
287
|
-
})
|
|
288
|
-
);
|
|
289
|
-
} else if (!createdUser.token) {
|
|
290
|
-
reject(
|
|
291
|
-
new OkHiException({
|
|
292
|
-
code: OkHiException.UNAUTHORIZED_CODE,
|
|
293
|
-
message: OkHiException.UNAUTHORIZED_MESSAGE,
|
|
294
|
-
})
|
|
295
|
-
);
|
|
296
|
-
} else {
|
|
297
|
-
const usageTypes: UsageType = Array.isArray(location.usageTypes)
|
|
298
|
-
? location.usageTypes
|
|
299
|
-
: ['digital_verification'];
|
|
300
|
-
sv(
|
|
301
|
-
createdUser.token,
|
|
302
|
-
createdUser.phone,
|
|
303
|
-
createdUser.id,
|
|
304
|
-
location.id,
|
|
305
|
-
location.lat,
|
|
306
|
-
location.lon,
|
|
307
|
-
usageTypes
|
|
308
|
-
)
|
|
309
|
-
.then(resolve)
|
|
310
|
-
.catch(reject);
|
|
311
|
-
}
|
|
312
|
-
});
|
|
313
|
-
},
|
|
314
|
-
});
|
|
315
|
-
} else if (response.message === 'request_location_permission') {
|
|
316
|
-
handleRequestLocationPermission(response.payload);
|
|
317
|
-
} else if (response.message === 'open_app_settings') {
|
|
318
|
-
handleOpenAppSettings();
|
|
319
|
-
} else if (response.message === 'fetch_current_location') {
|
|
320
|
-
handleFetchCurrentLocation();
|
|
321
|
-
}
|
|
322
|
-
} catch (error) {
|
|
323
|
-
let errorMessage = 'Something went wrong';
|
|
324
|
-
if (error instanceof Error) {
|
|
325
|
-
errorMessage = error.message;
|
|
326
|
-
}
|
|
327
|
-
onError(
|
|
328
|
-
new OkHiException({
|
|
329
|
-
code: OkHiException.UNKNOWN_ERROR_CODE,
|
|
330
|
-
message: errorMessage,
|
|
331
|
-
})
|
|
332
|
-
);
|
|
333
|
-
}
|
|
334
|
-
};
|
|
335
|
-
|
|
336
|
-
const handleOnError = () => {
|
|
337
|
-
onError(
|
|
338
|
-
new OkHiException({
|
|
339
|
-
code: OkHiException.NETWORK_ERROR_CODE,
|
|
340
|
-
message: OkHiException.NETWORK_ERROR_MESSAGE,
|
|
341
|
-
})
|
|
342
|
-
);
|
|
343
|
-
};
|
|
344
|
-
|
|
345
|
-
const handleModalRequestClose = () => {
|
|
346
|
-
webViewRef.current?.goBack();
|
|
347
|
-
};
|
|
348
|
-
|
|
349
|
-
const renderContent = () => {
|
|
350
|
-
if (startPayload === null || applicationConfiguration == null) {
|
|
351
|
-
return loader || <Spinner />;
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
const { jsAfterLoad, jsBeforeLoad } = generateJavaScriptStartScript({
|
|
355
|
-
message: startMessage,
|
|
356
|
-
payload: startPayload,
|
|
357
|
-
});
|
|
358
|
-
|
|
359
|
-
return (
|
|
360
|
-
<SafeAreaView style={style}>
|
|
361
|
-
<WebView
|
|
362
|
-
source={{ uri: getFrameUrl(applicationConfiguration) }}
|
|
363
|
-
injectedJavaScriptBeforeContentLoaded={
|
|
364
|
-
Platform.OS === 'ios' ? jsBeforeLoad : undefined
|
|
365
|
-
}
|
|
366
|
-
injectedJavaScript={Platform.OS === 'ios' ? undefined : jsAfterLoad}
|
|
367
|
-
onMessage={handleOnMessage}
|
|
368
|
-
onError={handleOnError}
|
|
369
|
-
onHttpError={handleOnError}
|
|
370
|
-
geolocationEnabled={true}
|
|
371
|
-
allowsBackForwardNavigationGestures={true}
|
|
372
|
-
onLoad={handleWebViewOnLoad}
|
|
373
|
-
ref={webViewRef}
|
|
374
|
-
/>
|
|
375
|
-
</SafeAreaView>
|
|
376
|
-
);
|
|
377
|
-
};
|
|
378
|
-
|
|
379
|
-
return (
|
|
380
|
-
<Modal
|
|
381
|
-
animationType="slide"
|
|
382
|
-
transparent={false}
|
|
383
|
-
visible={ready}
|
|
384
|
-
onRequestClose={handleModalRequestClose}
|
|
385
|
-
>
|
|
386
|
-
{ready ? renderContent() : null}
|
|
387
|
-
</Modal>
|
|
388
|
-
);
|
|
389
|
-
};
|
|
390
|
-
|
|
391
|
-
export default OkHiLocationManager;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { ActivityIndicator, View, ViewStyle } from 'react-native';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Default spinner component that'll be used as the initial loading indicator.
|
|
6
|
-
*/
|
|
7
|
-
export const Spinner = () => {
|
|
8
|
-
const style: ViewStyle = {
|
|
9
|
-
flex: 1,
|
|
10
|
-
alignItems: 'center',
|
|
11
|
-
justifyContent: 'center',
|
|
12
|
-
};
|
|
13
|
-
return (
|
|
14
|
-
<View style={style}>
|
|
15
|
-
<ActivityIndicator color="teal" size="small" />
|
|
16
|
-
</View>
|
|
17
|
-
);
|
|
18
|
-
};
|
package/src/OkCollect/Util.ts
DELETED
|
@@ -1,270 +0,0 @@
|
|
|
1
|
-
import type { OkHiLocationManagerProps } from './types';
|
|
2
|
-
import {
|
|
3
|
-
canOpenProtectedAppsSettings,
|
|
4
|
-
isBackgroundLocationPermissionGranted,
|
|
5
|
-
isLocationPermissionGranted,
|
|
6
|
-
OkHiException,
|
|
7
|
-
OkHiLocation,
|
|
8
|
-
} from '../OkCore';
|
|
9
|
-
import { OkHiMode } from '../OkCore';
|
|
10
|
-
import type {
|
|
11
|
-
OkHiLocationManagerStartDataPayload,
|
|
12
|
-
OkHiLocationManagerStartMessage,
|
|
13
|
-
} from './types';
|
|
14
|
-
import manifest from './app.json'; //TODO: fix this
|
|
15
|
-
import type { AuthApplicationConfig } from '../OkCore/_types';
|
|
16
|
-
import { Platform } from 'react-native';
|
|
17
|
-
import { OkHiNativeModule } from '../OkHiNativeModule';
|
|
18
|
-
|
|
19
|
-
export const fetchCurrentLocation = async (): Promise<null | {
|
|
20
|
-
lat: number;
|
|
21
|
-
lng: number;
|
|
22
|
-
accuracy: number;
|
|
23
|
-
}> => {
|
|
24
|
-
const result = await OkHiNativeModule.fetchCurrentLocation();
|
|
25
|
-
return result;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* @ignore
|
|
30
|
-
*/
|
|
31
|
-
export const generateStartDataPayload = async (
|
|
32
|
-
props: OkHiLocationManagerProps,
|
|
33
|
-
applicationConfiguration: AuthApplicationConfig
|
|
34
|
-
): Promise<OkHiLocationManagerStartDataPayload> => {
|
|
35
|
-
const payload: any = {};
|
|
36
|
-
const { manufacturer, model, osVersion, platform } =
|
|
37
|
-
await OkHiNativeModule.retrieveDeviceInfo();
|
|
38
|
-
const geofences = await OkHiNativeModule.fetchRegisteredGeofences();
|
|
39
|
-
const locationAccuracyLevel =
|
|
40
|
-
await OkHiNativeModule.getLocationAccuracyLevel();
|
|
41
|
-
|
|
42
|
-
if (geofences) {
|
|
43
|
-
payload.locations = JSON.parse(geofences);
|
|
44
|
-
}
|
|
45
|
-
payload.style = !props.theme
|
|
46
|
-
? undefined
|
|
47
|
-
: {
|
|
48
|
-
base: {
|
|
49
|
-
color: props.theme?.colors?.primary,
|
|
50
|
-
logo: props.theme?.appBar?.logo,
|
|
51
|
-
name: applicationConfiguration.app?.name,
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
|
-
payload.user = {
|
|
55
|
-
phone: props.user.phone,
|
|
56
|
-
firstName: props.user.firstName,
|
|
57
|
-
lastName: props.user.lastName,
|
|
58
|
-
email: props.user.email,
|
|
59
|
-
appUserId: props.user.appUserId,
|
|
60
|
-
};
|
|
61
|
-
payload.auth = {
|
|
62
|
-
branchId: applicationConfiguration.credentials.branchId,
|
|
63
|
-
clientKey: applicationConfiguration.credentials.clientKey,
|
|
64
|
-
};
|
|
65
|
-
payload.context = {
|
|
66
|
-
container: {
|
|
67
|
-
name: applicationConfiguration.app?.name,
|
|
68
|
-
version: applicationConfiguration.app?.version,
|
|
69
|
-
},
|
|
70
|
-
developer: {
|
|
71
|
-
name: applicationConfiguration.context.developer,
|
|
72
|
-
},
|
|
73
|
-
library: {
|
|
74
|
-
name: manifest.name,
|
|
75
|
-
version: manifest.version,
|
|
76
|
-
},
|
|
77
|
-
platform: {
|
|
78
|
-
name: 'react-native',
|
|
79
|
-
},
|
|
80
|
-
device: {
|
|
81
|
-
manufacturer,
|
|
82
|
-
model,
|
|
83
|
-
platform,
|
|
84
|
-
osVersion,
|
|
85
|
-
},
|
|
86
|
-
locationAccuracyLevel,
|
|
87
|
-
};
|
|
88
|
-
payload.config = {
|
|
89
|
-
streetView:
|
|
90
|
-
typeof props.config?.streetView === 'boolean'
|
|
91
|
-
? props.config.streetView
|
|
92
|
-
: true,
|
|
93
|
-
appBar: {
|
|
94
|
-
color: props.theme?.appBar?.backgroundColor,
|
|
95
|
-
visible: props.config?.appBar?.visible,
|
|
96
|
-
},
|
|
97
|
-
addressTypes: {
|
|
98
|
-
home:
|
|
99
|
-
typeof props.config?.addressTypes?.home === 'boolean'
|
|
100
|
-
? props.config?.addressTypes?.home
|
|
101
|
-
: true,
|
|
102
|
-
work:
|
|
103
|
-
typeof props.config?.addressTypes?.work === 'boolean'
|
|
104
|
-
? props.config?.addressTypes?.work
|
|
105
|
-
: true,
|
|
106
|
-
},
|
|
107
|
-
protectedApps:
|
|
108
|
-
Platform.OS === 'android' && (await canOpenProtectedAppsSettings()),
|
|
109
|
-
permissionsOnboarding: true,
|
|
110
|
-
usageTypes: props.config?.usageTypes || ['digital_verification'],
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
if (Platform.OS === 'ios') {
|
|
114
|
-
const status = await OkHiNativeModule.fetchIOSLocationPermissionStatus();
|
|
115
|
-
const locationPermission =
|
|
116
|
-
status === 'notDetermined'
|
|
117
|
-
? 'notDetermined'
|
|
118
|
-
: status === 'authorizedWhenInUse'
|
|
119
|
-
? 'whenInUse'
|
|
120
|
-
: status === 'authorizedAlways'
|
|
121
|
-
? 'always'
|
|
122
|
-
: 'denied';
|
|
123
|
-
payload.context.permissions = {
|
|
124
|
-
location: locationPermission,
|
|
125
|
-
};
|
|
126
|
-
if (
|
|
127
|
-
status === 'authorized' ||
|
|
128
|
-
status === 'authorizedWhenInUse' ||
|
|
129
|
-
status === 'authorizedAlways'
|
|
130
|
-
) {
|
|
131
|
-
const location = await fetchCurrentLocation();
|
|
132
|
-
if (location) {
|
|
133
|
-
payload.context.coordinates = {
|
|
134
|
-
currentLocation: {
|
|
135
|
-
lat: location.lat,
|
|
136
|
-
lng: location.lng,
|
|
137
|
-
accuracy: location.accuracy,
|
|
138
|
-
},
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
} else if (Platform.OS === 'android') {
|
|
143
|
-
let hasLocationPermission: boolean | undefined;
|
|
144
|
-
try {
|
|
145
|
-
hasLocationPermission = await isLocationPermissionGranted();
|
|
146
|
-
} catch (error) {
|
|
147
|
-
console.log(error);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
let hasBackgroundLocationPermission: boolean | undefined;
|
|
151
|
-
try {
|
|
152
|
-
hasBackgroundLocationPermission =
|
|
153
|
-
await isBackgroundLocationPermissionGranted();
|
|
154
|
-
} catch (error) {
|
|
155
|
-
console.log(error);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
if (
|
|
159
|
-
typeof hasLocationPermission === 'boolean' &&
|
|
160
|
-
typeof hasBackgroundLocationPermission === 'boolean'
|
|
161
|
-
) {
|
|
162
|
-
payload.context.permissions = {
|
|
163
|
-
location: hasBackgroundLocationPermission
|
|
164
|
-
? 'always'
|
|
165
|
-
: hasLocationPermission
|
|
166
|
-
? 'whenInUse'
|
|
167
|
-
: 'denied',
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
} else {
|
|
171
|
-
throw new OkHiException({
|
|
172
|
-
code: OkHiException.UNSUPPORTED_PLATFORM_CODE,
|
|
173
|
-
message: OkHiException.UNAUTHORIZED_MESSAGE,
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
if (props.location?.id) {
|
|
178
|
-
payload.location = {
|
|
179
|
-
id: props.location.id,
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
return payload;
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* @ignore
|
|
188
|
-
*/
|
|
189
|
-
export const getFrameUrl = (
|
|
190
|
-
applicationConfiguration: AuthApplicationConfig
|
|
191
|
-
): string => {
|
|
192
|
-
const DEV_FRAME_URL = 'https://dev-manager-v5.okhi.io';
|
|
193
|
-
const PROD_FRAME_URL = 'https://manager-v5.okhi.io';
|
|
194
|
-
const SANDBOX_FRAME_URL = 'https://sandbox-manager-v5.okhi.io';
|
|
195
|
-
|
|
196
|
-
const LEGACY_DEV_FRAME_URL = 'https://dev-legacy-manager-v5.okhi.io';
|
|
197
|
-
const LEGACY_PROD_FRAME_URL = 'https://legacy-manager-v5.okhi.io';
|
|
198
|
-
const LEGACY_SANDBOX_FRAME_URL = 'https://sandbox-legacy-manager-v5.okhi.io';
|
|
199
|
-
|
|
200
|
-
if (Platform.OS === 'android' && Platform.Version < 24) {
|
|
201
|
-
if (applicationConfiguration.context.mode === OkHiMode.PROD) {
|
|
202
|
-
return LEGACY_PROD_FRAME_URL;
|
|
203
|
-
}
|
|
204
|
-
if (applicationConfiguration.context.mode === ('dev' as any)) {
|
|
205
|
-
return LEGACY_DEV_FRAME_URL;
|
|
206
|
-
}
|
|
207
|
-
return LEGACY_SANDBOX_FRAME_URL;
|
|
208
|
-
}
|
|
209
|
-
if (applicationConfiguration.context.mode === OkHiMode.PROD) {
|
|
210
|
-
return PROD_FRAME_URL;
|
|
211
|
-
}
|
|
212
|
-
if (applicationConfiguration.context.mode === ('dev' as any)) {
|
|
213
|
-
return DEV_FRAME_URL;
|
|
214
|
-
}
|
|
215
|
-
return SANDBOX_FRAME_URL;
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* @ignore
|
|
220
|
-
*/
|
|
221
|
-
export const generateJavaScriptStartScript = (startPayload: {
|
|
222
|
-
message: OkHiLocationManagerStartMessage;
|
|
223
|
-
payload: OkHiLocationManagerStartDataPayload;
|
|
224
|
-
}) => {
|
|
225
|
-
const jsBeforeLoad = `
|
|
226
|
-
window.isNativeApp = true;
|
|
227
|
-
window.NativeApp = {
|
|
228
|
-
bridge: {
|
|
229
|
-
receiveMessage: window.ReactNativeWebView.postMessage
|
|
230
|
-
},
|
|
231
|
-
data: ${JSON.stringify(startPayload)}
|
|
232
|
-
}
|
|
233
|
-
true;
|
|
234
|
-
`;
|
|
235
|
-
const jsAfterLoad = `window.startOkHiLocationManager({ receiveMessage: function(data) { window.ReactNativeWebView.postMessage(data) } }, ${JSON.stringify(
|
|
236
|
-
startPayload
|
|
237
|
-
)})`;
|
|
238
|
-
return { jsBeforeLoad, jsAfterLoad };
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* @ignore
|
|
243
|
-
*/
|
|
244
|
-
export const parseOkHiLocation = (location: any): OkHiLocation => {
|
|
245
|
-
return {
|
|
246
|
-
id: location?.id,
|
|
247
|
-
lat: location?.geo_point?.lat,
|
|
248
|
-
lon: location?.geo_point?.lon,
|
|
249
|
-
placeId: location?.place_id,
|
|
250
|
-
plusCode: location?.plus_code,
|
|
251
|
-
propertyName: location?.property_name,
|
|
252
|
-
streetName: location?.street_name,
|
|
253
|
-
title: location?.title,
|
|
254
|
-
subtitle: location?.subtitle,
|
|
255
|
-
directions: location?.directions,
|
|
256
|
-
otherInformation: location?.other_information,
|
|
257
|
-
url: location?.url,
|
|
258
|
-
streetViewPanoId: location?.street_view?.pano_id,
|
|
259
|
-
streetViewPanoUrl: location?.street_view?.url,
|
|
260
|
-
userId: location?.user_id,
|
|
261
|
-
propertyNumber: location?.propertyNumber,
|
|
262
|
-
photo: location?.photo,
|
|
263
|
-
displayTitle: location?.display_title,
|
|
264
|
-
country: location?.country,
|
|
265
|
-
state: location?.state,
|
|
266
|
-
city: location?.city,
|
|
267
|
-
countryCode: location?.country_code,
|
|
268
|
-
usageTypes: location?.usage_types,
|
|
269
|
-
};
|
|
270
|
-
};
|
package/src/OkCollect/app.json
DELETED
package/src/OkCollect/index.ts
DELETED