react-native-okhi 1.2.2 → 1.2.3-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.
@@ -278,6 +278,8 @@ public class OkhiModule extends ReactContextBaseJavaModule {
278
278
  WritableMap map = new WritableNativeMap();
279
279
  map.putString("manufacturer", Build.MANUFACTURER);
280
280
  map.putString("model", Build.MODEL);
281
+ map.putString("osVersion", Build.VERSION.RELEASE);
282
+ map.putString("platform", "android");
281
283
  promise.resolve(map);
282
284
  }
283
285
 
package/ios/Okhi.m CHANGED
@@ -47,4 +47,5 @@ RCT_EXTERN_METHOD(fetchCurrentLocation: (RCTPromiseResolveBlock)resolve reject:(
47
47
 
48
48
  RCT_EXTERN_METHOD(fetchIOSLocationPermissionStatus: (RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
49
49
 
50
+ RCT_EXTERN_METHOD(retrieveDeviceInfo: (RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
50
51
  @end
package/ios/Okhi.swift CHANGED
@@ -145,6 +145,16 @@ class Okhi: RCTEventEmitter {
145
145
  }
146
146
  }
147
147
 
148
+ @objc func retrieveDeviceInfo(_ resolve:@escaping RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) {
149
+ let deviceInfoDict: NSDictionary = [
150
+ "manufacturer": "Apple",
151
+ "model": UIDevice.current.modelName,
152
+ "osVersion": UIDevice.current.systemVersion,
153
+ "platform": "ios"
154
+ ]
155
+ resolve(deviceInfoDict)
156
+ }
157
+
148
158
  override func supportedEvents() -> [String]! {
149
159
  return ["onLocationPermissionStatusUpdate"]
150
160
  }
@@ -242,3 +252,17 @@ extension Okhi: OkVerifyDelegate {
242
252
 
243
253
  }
244
254
  }
255
+
256
+ extension UIDevice {
257
+ var modelName: String {
258
+ var systemInfo = utsname()
259
+ uname(&systemInfo)
260
+ let machineMirror = Mirror(reflecting: systemInfo.machine)
261
+ let identifier = machineMirror.children.reduce("") { identifier, element in
262
+ guard let value = element.value as? Int8, value != 0 else { return identifier }
263
+ return identifier + String(UnicodeScalar(UInt8(value)))
264
+ }
265
+ return identifier
266
+ }
267
+ }
268
+
@@ -89,12 +89,75 @@ const OkHiLocationManager = props => {
89
89
  }
90
90
  }, [applicationConfiguration, props, token]);
91
91
 
92
- const handleOnMessage = _ref => {
92
+ const runWebViewCallback = value => {
93
+ if (webViewRef.current) {
94
+ const jsString = `(function (){ if (typeof runOkHiLocationManagerCallback === "function") { runOkHiLocationManagerCallback("${value}") } })()`;
95
+ webViewRef.current.injectJavaScript(jsString);
96
+ }
97
+ };
98
+
99
+ const handleAndroidRequestLocationPermission = async level => {
100
+ // using request for android because we can programmatically turn on location services, unlike yucky ios
101
+ (0, _OkCore.request)(level, null, (status, error) => {
102
+ if (error) {
103
+ onError(error);
104
+ } else if (level === 'whenInUse' && status === 'authorizedWhenInUse') {
105
+ runWebViewCallback(level);
106
+ } else if (level === 'always' && status === 'authorizedAlways') {
107
+ runWebViewCallback(level);
108
+ }
109
+ });
110
+ };
111
+
112
+ const handleIOSRequestLocationPermission = async level => {
113
+ const serviceError = new _OkHiException.OkHiException({
114
+ code: _OkHiException.OkHiException.SERVICE_UNAVAILABLE_CODE,
115
+ message: 'Location service is currently not available. Please enable in app settings'
116
+ });
117
+ const unknownError = new _OkHiException.OkHiException({
118
+ code: _OkHiException.OkHiException.UNKNOWN_ERROR_CODE,
119
+ message: 'Something went wrong while requesting permissions. Please try again later.'
120
+ });
121
+
122
+ try {
123
+ const isServiceAvailable = await (0, _OkCore.isLocationServicesEnabled)();
124
+
125
+ if (!isServiceAvailable) {
126
+ onError(serviceError);
127
+ } else if (level === 'whenInUse' && (await (0, _OkCore.requestLocationPermission)())) {
128
+ runWebViewCallback(level);
129
+ } else if (level === 'always') {
130
+ const granted = await (0, _OkCore.isBackgroundLocationPermissionGranted)();
131
+
132
+ if (granted) {
133
+ runWebViewCallback(level);
134
+ } else {
135
+ (0, _OkCore.openAppSettings)();
136
+ }
137
+ }
138
+ } catch (error) {
139
+ onError(unknownError);
140
+ }
141
+ };
142
+
143
+ const handleRequestLocationPermission = async _ref => {
144
+ let {
145
+ level
146
+ } = _ref;
147
+
148
+ if (_reactNative.Platform.OS === 'android') {
149
+ handleAndroidRequestLocationPermission(level);
150
+ } else if (_reactNative.Platform.OS === 'ios') {
151
+ handleIOSRequestLocationPermission(level);
152
+ }
153
+ };
154
+
155
+ const handleOnMessage = _ref2 => {
93
156
  let {
94
157
  nativeEvent: {
95
158
  data
96
159
  }
97
- } = _ref;
160
+ } = _ref2;
98
161
 
99
162
  try {
100
163
  const response = JSON.parse(data);
@@ -102,13 +165,13 @@ const OkHiLocationManager = props => {
102
165
  if (response.message === 'fatal_exit') {
103
166
  onError(new _OkHiException.OkHiException({
104
167
  code: _OkHiException.OkHiException.UNKNOWN_ERROR_CODE,
105
- message: response.payload.toString()
168
+ message: 'Something went wrong, please try again later.'
106
169
  }));
107
170
  } else if (response.message === 'exit_app') {
108
171
  onCloseRequest();
109
172
  } else if (response.message === 'request_enable_protected_apps') {
110
173
  (0, _OkCore.openProtectedAppsSettings)();
111
- } else {
174
+ } else if (response.message === 'location_created' || response.message === 'location_selected' || response.message === 'location_updated') {
112
175
  onSuccess({
113
176
  user: { ...response.payload.user,
114
177
  fcmPushNotificationToken: user.fcmPushNotificationToken
@@ -131,6 +194,8 @@ const OkHiLocationManager = props => {
131
194
  });
132
195
  }
133
196
  });
197
+ } else if (response.message === 'request_location_permission') {
198
+ handleRequestLocationPermission(response.payload);
134
199
  }
135
200
  } catch (error) {
136
201
  let errorMessage = 'Something went wrong';
@@ -1 +1 @@
1
- {"version":3,"names":["OkHiLocationManager","props","token","setToken","useState","applicationConfiguration","setApplicationConfiguration","startPayload","setStartPaylaod","defaultStyle","flex","style","user","onSuccess","onCloseRequest","onError","loader","launch","webViewRef","useRef","startMessage","mode","useEffect","phone","getApplicationConfiguration","then","config","OkHiException","code","UNAUTHORIZED_CODE","message","UNAUTHORIZED_MESSAGE","auth","OkHiAuth","anonymousSignInWithPhoneNumber","catch","error","generateStartDataPayload","Platform","OS","Version","OkHiNativeModule","setItem","JSON","stringify","payload","url","getFrameUrl","console","handleOnMessage","nativeEvent","data","response","parse","UNKNOWN_ERROR_CODE","toString","openProtectedAppsSettings","fcmPushNotificationToken","location","parseOkHiLocation","startVerification","createdUser","Promise","resolve","reject","id","BAD_REQUEST_CODE","sv","lat","lon","errorMessage","Error","handleOnError","NETWORK_ERROR_CODE","NETWORK_ERROR_MESSAGE","handleModalRequestClose","current","goBack","renderContent","jsAfterLoad","jsBeforeLoad","generateJavaScriptStartScript","uri","undefined"],"sources":["OkHiLocationManager.tsx"],"sourcesContent":["import React, { useState, useEffect, useRef } from 'react';\nimport { Modal, SafeAreaView, Platform } from 'react-native';\nimport { WebView, WebViewMessageEvent } from 'react-native-webview';\nimport { Spinner } from './Spinner';\nimport type {\n OkHiLocationManagerResponse,\n OkHiLocationManagerProps,\n OkHiLocationManagerStartDataPayload,\n} from './types';\nimport {\n getFrameUrl,\n generateJavaScriptStartScript,\n generateStartDataPayload,\n parseOkHiLocation,\n} from './Util';\nimport { OkHiException } from '../OkCore/OkHiException';\nimport { OkHiAuth } from '../OkCore/OkHiAuth';\nimport type { AuthApplicationConfig } from '../OkCore/_types';\nimport { start as sv } from '../OkVerify';\nimport type { OkVerifyStartConfiguration } from '../OkVerify/types';\nimport {\n getApplicationConfiguration,\n openProtectedAppsSettings,\n} from '../OkCore';\nimport { OkHiNativeModule } from '../OkHiNativeModule';\n\n/**\n * The OkHiLocationManager React Component is used to display an in app modal, enabling the user to quickly create an accurate OkHi address.\n */\nexport const OkHiLocationManager = (props: OkHiLocationManagerProps) => {\n const [token, setToken] = useState<string | null>(null);\n const [applicationConfiguration, setApplicationConfiguration] =\n useState<AuthApplicationConfig | null>(null);\n const [startPayload, setStartPaylaod] =\n useState<null | OkHiLocationManagerStartDataPayload>(null);\n const defaultStyle = { flex: 1 };\n const style = props.style\n ? { ...props.style, ...defaultStyle }\n : defaultStyle;\n\n const { user, onSuccess, onCloseRequest, onError, loader, launch } = props;\n const webViewRef = useRef<WebView | null>(null);\n const startMessage =\n props.mode === 'create' ? 'start_app' : 'select_location';\n\n useEffect(() => {\n if (applicationConfiguration == null && token == null && user.phone) {\n getApplicationConfiguration()\n .then((config) => {\n if (!config && launch) {\n onError(\n new OkHiException({\n code: OkHiException.UNAUTHORIZED_CODE,\n message: OkHiException.UNAUTHORIZED_MESSAGE,\n })\n );\n } else if (config) {\n setApplicationConfiguration(config);\n const auth = new OkHiAuth();\n auth\n .anonymousSignInWithPhoneNumber(user.phone, ['verify'], config)\n .then(setToken)\n .catch(onError);\n }\n })\n .catch((error) => {\n if (launch) {\n onError(error);\n }\n });\n }\n }, [onError, user.phone, launch, applicationConfiguration, token]);\n\n useEffect(() => {\n if (token !== null && applicationConfiguration !== null) {\n // TODO: handle faliure\n generateStartDataPayload(props, token, applicationConfiguration)\n .then((startPayload) => {\n setStartPaylaod(startPayload);\n if (Platform.OS === 'android' && Platform.Version > 25) {\n OkHiNativeModule.setItem(\n 'okcollect-launch-payload',\n JSON.stringify({\n message: startMessage,\n payload: startPayload,\n url: getFrameUrl(applicationConfiguration),\n })\n ).catch(console.error);\n }\n })\n .catch(console.error);\n }\n }, [applicationConfiguration, props, token]);\n\n const handleOnMessage = ({ nativeEvent: { data } }: WebViewMessageEvent) => {\n try {\n const response: OkHiLocationManagerResponse = JSON.parse(data);\n if (response.message === 'fatal_exit') {\n onError(\n new OkHiException({\n code: OkHiException.UNKNOWN_ERROR_CODE,\n message: response.payload.toString(),\n })\n );\n } else if (response.message === 'exit_app') {\n onCloseRequest();\n } else if (response.message === 'request_enable_protected_apps') {\n openProtectedAppsSettings();\n } else {\n onSuccess({\n user: {\n ...response.payload.user,\n fcmPushNotificationToken: user.fcmPushNotificationToken,\n },\n location: parseOkHiLocation(response.payload.location),\n startVerification: function (config?: OkVerifyStartConfiguration) {\n const createdUser = { ...this.user };\n const location = { ...this.location };\n return new Promise((resolve, reject) => {\n if (!location.id) {\n reject(\n new OkHiException({\n code: OkHiException.BAD_REQUEST_CODE,\n message: 'Missing location id from response',\n })\n );\n } else {\n sv(\n createdUser.phone,\n location.id,\n location.lat,\n location.lon,\n config,\n createdUser.fcmPushNotificationToken\n )\n .then(resolve)\n .catch(reject);\n }\n });\n },\n });\n }\n } catch (error) {\n let errorMessage = 'Something went wrong';\n if (error instanceof Error) {\n errorMessage = error.message;\n }\n onError(\n new OkHiException({\n code: OkHiException.UNKNOWN_ERROR_CODE,\n message: errorMessage,\n })\n );\n }\n };\n\n const handleOnError = () => {\n onError(\n new OkHiException({\n code: OkHiException.NETWORK_ERROR_CODE,\n message: OkHiException.NETWORK_ERROR_MESSAGE,\n })\n );\n };\n\n const handleModalRequestClose = () => {\n webViewRef.current?.goBack();\n };\n\n const renderContent = () => {\n if (token === null || applicationConfiguration == null) {\n return loader || <Spinner />;\n }\n\n if (startPayload === null) {\n return loader || <Spinner />;\n }\n\n const { jsAfterLoad, jsBeforeLoad } = generateJavaScriptStartScript({\n message: startMessage,\n payload: startPayload,\n });\n\n return (\n <SafeAreaView style={style}>\n <WebView\n source={{ uri: getFrameUrl(applicationConfiguration) }}\n injectedJavaScriptBeforeContentLoaded={\n Platform.OS === 'ios' ? jsBeforeLoad : undefined\n }\n injectedJavaScript={Platform.OS === 'ios' ? undefined : jsAfterLoad}\n onMessage={handleOnMessage}\n onError={handleOnError}\n onHttpError={handleOnError}\n geolocationEnabled={true}\n allowsBackForwardNavigationGestures={true}\n ref={webViewRef}\n />\n </SafeAreaView>\n );\n };\n\n return (\n <Modal\n animationType=\"slide\"\n transparent={false}\n visible={launch}\n onRequestClose={handleModalRequestClose}\n >\n {launch ? renderContent() : null}\n </Modal>\n );\n};\n\nexport default OkHiLocationManager;\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AAMA;;AAMA;;AACA;;AAEA;;AAEA;;AAIA;;;;;;AAEA;AACA;AACA;AACO,MAAMA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AA,EAAY1C,wBAAZ;MAAP,CADV;MAEE,qCAAqC,EACnCiC,qBAAA,CAASC,EAAT,KAAgB,KAAhB,GAAwByC,YAAxB,GAAuCG,SAH3C;MAKE,kBAAkB,EAAE7C,qBAAA,CAASC,EAAT,KAAgB,KAAhB,GAAwB4C,SAAxB,GAAoCJ,WAL1D;MAME,SAAS,EAAE9B,eANb;MAOE,OAAO,EAAEuB,aAPX;MAQE,WAAW,EAAEA,aARf;MASE,kBAAkB,EAAE,IATtB;MAUE,mCAAmC,EAAE,IAVvC;MAWE,GAAG,EAAEtD;IAXP,EADF,CADF;EAiBD,CA/BD;;EAiCA,oBACE,6BAAC,kBAAD;IACE,aAAa,EAAC,OADhB;IAEE,WAAW,EAAE,KAFf;IAGE,OAAO,EAAED,MAHX;IAIE,cAAc,EAAE0D;EAJlB,GAMG1D,MAAM,GAAG6D,aAAa,EAAhB,GAAqB,IAN9B,CADF;AAUD,CAvLM;;;eAyLQ9E,mB"}
1
+ {"version":3,"names":["OkHiLocationManager","props","token","setToken","useState","applicationConfiguration","setApplicationConfiguration","startPayload","setStartPaylaod","defaultStyle","flex","style","user","onSuccess","onCloseRequest","onError","loader","launch","webViewRef","useRef","startMessage","mode","useEffect","phone","getApplicationConfiguration","then","config","OkHiException","code","UNAUTHORIZED_CODE","message","UNAUTHORIZED_MESSAGE","auth","OkHiAuth","anonymousSignInWithPhoneNumber","catch","error","generateStartDataPayload","Platform","OS","Version","OkHiNativeModule","setItem","JSON","stringify","payload","url","getFrameUrl","console","runWebViewCallback","value","current","jsString","injectJavaScript","handleAndroidRequestLocationPermission","level","request","status","handleIOSRequestLocationPermission","serviceError","SERVICE_UNAVAILABLE_CODE","unknownError","UNKNOWN_ERROR_CODE","isServiceAvailable","isLocationServicesEnabled","requestLocationPermission","granted","isBackgroundLocationPermissionGranted","openAppSettings","handleRequestLocationPermission","handleOnMessage","nativeEvent","data","response","parse","openProtectedAppsSettings","fcmPushNotificationToken","location","parseOkHiLocation","startVerification","createdUser","Promise","resolve","reject","id","BAD_REQUEST_CODE","sv","lat","lon","errorMessage","Error","handleOnError","NETWORK_ERROR_CODE","NETWORK_ERROR_MESSAGE","handleModalRequestClose","goBack","renderContent","jsAfterLoad","jsBeforeLoad","generateJavaScriptStartScript","uri","undefined"],"sources":["OkHiLocationManager.tsx"],"sourcesContent":["import React, { useState, useEffect, useRef } from 'react';\nimport { Modal, SafeAreaView, Platform } from 'react-native';\nimport { WebView, WebViewMessageEvent } from 'react-native-webview';\nimport { Spinner } from './Spinner';\nimport type {\n OkHiLocationManagerResponse,\n OkHiLocationManagerProps,\n OkHiLocationManagerStartDataPayload,\n} from './types';\nimport {\n getFrameUrl,\n generateJavaScriptStartScript,\n generateStartDataPayload,\n parseOkHiLocation,\n} from './Util';\nimport { OkHiException } from '../OkCore/OkHiException';\nimport { OkHiAuth } from '../OkCore/OkHiAuth';\nimport type { AuthApplicationConfig } from '../OkCore/_types';\nimport { start as sv } from '../OkVerify';\nimport type { OkVerifyStartConfiguration } from '../OkVerify/types';\nimport {\n getApplicationConfiguration,\n isBackgroundLocationPermissionGranted,\n isLocationServicesEnabled,\n openAppSettings,\n openProtectedAppsSettings,\n request,\n requestLocationPermission,\n} from '../OkCore';\nimport { OkHiNativeModule } from '../OkHiNativeModule';\n\n/**\n * The OkHiLocationManager React Component is used to display an in app modal, enabling the user to quickly create an accurate OkHi address.\n */\nexport const OkHiLocationManager = (props: OkHiLocationManagerProps) => {\n const [token, setToken] = useState<string | null>(null);\n const [applicationConfiguration, setApplicationConfiguration] =\n useState<AuthApplicationConfig | null>(null);\n const [startPayload, setStartPaylaod] =\n useState<null | OkHiLocationManagerStartDataPayload>(null);\n const defaultStyle = { flex: 1 };\n const style = props.style\n ? { ...props.style, ...defaultStyle }\n : defaultStyle;\n\n const { user, onSuccess, onCloseRequest, onError, loader, launch } = props;\n const webViewRef = useRef<WebView | null>(null);\n const startMessage =\n props.mode === 'create' ? 'start_app' : 'select_location';\n\n useEffect(() => {\n if (applicationConfiguration == null && token == null && user.phone) {\n getApplicationConfiguration()\n .then((config) => {\n if (!config && launch) {\n onError(\n new OkHiException({\n code: OkHiException.UNAUTHORIZED_CODE,\n message: OkHiException.UNAUTHORIZED_MESSAGE,\n })\n );\n } else if (config) {\n setApplicationConfiguration(config);\n const auth = new OkHiAuth();\n auth\n .anonymousSignInWithPhoneNumber(user.phone, ['verify'], config)\n .then(setToken)\n .catch(onError);\n }\n })\n .catch((error) => {\n if (launch) {\n onError(error);\n }\n });\n }\n }, [onError, user.phone, launch, applicationConfiguration, token]);\n\n useEffect(() => {\n if (token !== null && applicationConfiguration !== null) {\n // TODO: handle faliure\n generateStartDataPayload(props, token, applicationConfiguration)\n .then((startPayload) => {\n setStartPaylaod(startPayload);\n if (Platform.OS === 'android' && Platform.Version > 25) {\n OkHiNativeModule.setItem(\n 'okcollect-launch-payload',\n JSON.stringify({\n message: startMessage,\n payload: startPayload,\n url: getFrameUrl(applicationConfiguration),\n })\n ).catch(console.error);\n }\n })\n .catch(console.error);\n }\n }, [applicationConfiguration, props, token]);\n\n const runWebViewCallback = (value: string) => {\n if (webViewRef.current) {\n const jsString = `(function (){ if (typeof runOkHiLocationManagerCallback === \"function\") { runOkHiLocationManagerCallback(\"${value}\") } })()`;\n webViewRef.current.injectJavaScript(jsString);\n }\n };\n\n const handleAndroidRequestLocationPermission = async (\n level: 'whenInUse' | 'always'\n ) => {\n // using request for android because we can programmatically turn on location services, unlike yucky ios\n request(level, null, (status, error) => {\n if (error) {\n onError(error);\n } else if (level === 'whenInUse' && status === 'authorizedWhenInUse') {\n runWebViewCallback(level);\n } else if (level === 'always' && status === 'authorizedAlways') {\n runWebViewCallback(level);\n }\n });\n };\n\n const handleIOSRequestLocationPermission = async (\n level: 'whenInUse' | 'always'\n ) => {\n const serviceError = new OkHiException({\n code: OkHiException.SERVICE_UNAVAILABLE_CODE,\n message:\n 'Location service is currently not available. Please enable in app settings',\n });\n const unknownError = new OkHiException({\n code: OkHiException.UNKNOWN_ERROR_CODE,\n message:\n 'Something went wrong while requesting permissions. Please try again later.',\n });\n try {\n const isServiceAvailable = await isLocationServicesEnabled();\n if (!isServiceAvailable) {\n onError(serviceError);\n } else if (level === 'whenInUse' && (await requestLocationPermission())) {\n runWebViewCallback(level);\n } else if (level === 'always') {\n const granted = await isBackgroundLocationPermissionGranted();\n if (granted) {\n runWebViewCallback(level);\n } else {\n openAppSettings();\n }\n }\n } catch (error) {\n onError(unknownError);\n }\n };\n\n const handleRequestLocationPermission = async ({\n level,\n }: {\n level: 'whenInUse' | 'always';\n }) => {\n if (Platform.OS === 'android') {\n handleAndroidRequestLocationPermission(level);\n } else if (Platform.OS === 'ios') {\n handleIOSRequestLocationPermission(level);\n }\n };\n\n const handleOnMessage = ({ nativeEvent: { data } }: WebViewMessageEvent) => {\n try {\n const response: OkHiLocationManagerResponse = JSON.parse(data);\n if (response.message === 'fatal_exit') {\n onError(\n new OkHiException({\n code: OkHiException.UNKNOWN_ERROR_CODE,\n message: 'Something went wrong, please try again later.',\n })\n );\n } else if (response.message === 'exit_app') {\n onCloseRequest();\n } else if (response.message === 'request_enable_protected_apps') {\n openProtectedAppsSettings();\n } else if (\n response.message === 'location_created' ||\n response.message === 'location_selected' ||\n response.message === 'location_updated'\n ) {\n onSuccess({\n user: {\n ...response.payload.user,\n fcmPushNotificationToken: user.fcmPushNotificationToken,\n },\n location: parseOkHiLocation(response.payload.location),\n startVerification: function (config?: OkVerifyStartConfiguration) {\n const createdUser = { ...this.user };\n const location = { ...this.location };\n return new Promise((resolve, reject) => {\n if (!location.id) {\n reject(\n new OkHiException({\n code: OkHiException.BAD_REQUEST_CODE,\n message: 'Missing location id from response',\n })\n );\n } else {\n sv(\n createdUser.phone,\n location.id,\n location.lat,\n location.lon,\n config,\n createdUser.fcmPushNotificationToken\n )\n .then(resolve)\n .catch(reject);\n }\n });\n },\n });\n } else if (response.message === 'request_location_permission') {\n handleRequestLocationPermission(response.payload);\n }\n } catch (error) {\n let errorMessage = 'Something went wrong';\n if (error instanceof Error) {\n errorMessage = error.message;\n }\n onError(\n new OkHiException({\n code: OkHiException.UNKNOWN_ERROR_CODE,\n message: errorMessage,\n })\n );\n }\n };\n\n const handleOnError = () => {\n onError(\n new OkHiException({\n code: OkHiException.NETWORK_ERROR_CODE,\n message: OkHiException.NETWORK_ERROR_MESSAGE,\n })\n );\n };\n\n const handleModalRequestClose = () => {\n webViewRef.current?.goBack();\n };\n\n const renderContent = () => {\n if (token === null || applicationConfiguration == null) {\n return loader || <Spinner />;\n }\n\n if (startPayload === null) {\n return loader || <Spinner />;\n }\n\n const { jsAfterLoad, jsBeforeLoad } = generateJavaScriptStartScript({\n message: startMessage,\n payload: startPayload,\n });\n\n return (\n <SafeAreaView style={style}>\n <WebView\n source={{ uri: getFrameUrl(applicationConfiguration) }}\n injectedJavaScriptBeforeContentLoaded={\n Platform.OS === 'ios' ? jsBeforeLoad : undefined\n }\n injectedJavaScript={Platform.OS === 'ios' ? undefined : jsAfterLoad}\n onMessage={handleOnMessage}\n onError={handleOnError}\n onHttpError={handleOnError}\n geolocationEnabled={true}\n allowsBackForwardNavigationGestures={true}\n ref={webViewRef}\n />\n </SafeAreaView>\n );\n };\n\n return (\n <Modal\n animationType=\"slide\"\n transparent={false}\n visible={launch}\n onRequestClose={handleModalRequestClose}\n >\n {launch ? renderContent() : null}\n </Modal>\n );\n};\n\nexport default OkHiLocationManager;\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AAMA;;AAMA;;AACA;;AAEA;;AAEA;;AASA;;;;;;AAEA;AACA;AACA;AACO,MAAMA,mBAAmB,GAAIC,KAAD,IAAqC;EACtE,MAAM,CAACC,KAAD,EAAQC,QAAR,IAAoB,IAAAC,eAAA,EAAwB,IAAxB,CAA1B;EACA,MAAM,CAACC,wBAAD,EAA2BC,2BAA3B,IACJ,IAAAF,eAAA,EAAuC,IAAvC,CADF;EAEA,MAAM,CAACG,YAAD,EAAeC,eAAf,IACJ,IAAAJ,eAAA,EAAqD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,CAACiC,OAAX,4EAAoB4C,MAApB;EACD,CAFD;;EAIA,MAAMC,aAAa,GAAG,MAAM;IAC1B,IAAI9F,KAAK,KAAK,IAAV,IAAkBG,wBAAwB,IAAI,IAAlD,EAAwD;MACtD,OAAOW,MAAM,iBAAI,6BAAC,gBAAD,OAAjB;IACD;;IAED,IAAIT,YAAY,KAAK,IAArB,EAA2B;MACzB,OAAOS,MAAM,iBAAI,6BAAC,gBAAD,OAAjB;IACD;;IAED,MAAM;MAAEiF,WAAF;MAAeC;IAAf,IAAgC,IAAAC,mCAAA,EAA8B;MAClErE,OAAO,EAAEV,YADyD;MAElEyB,OAAO,EAAEtC;IAFyD,CAA9B,CAAtC;IAKA,oBACE,6BAAC,yBAAD;MAAc,KAAK,EAAEI;IAArB,gBACE,6BAAC,2BAAD;MACE,MAAM,EAAE;QAAEyF,GAAG,EAAE,IAAArD,iBAAA,EAAY1C,wBAAZ;MAAP,CADV;MAEE,qCAAqC,EACnCiC,qBAAA,CAASC,EAAT,KAAgB,KAAhB,GAAwB2D,YAAxB,GAAuCG,SAH3C;MAKE,kBAAkB,EAAE/D,qBAAA,CAASC,EAAT,KAAgB,KAAhB,GAAwB8D,SAAxB,GAAoCJ,WAL1D;MAME,SAAS,EAAE3B,eANb;MAOE,OAAO,EAAEqB,aAPX;MAQE,WAAW,EAAEA,aARf;MASE,kBAAkB,EAAE,IATtB;MAUE,mCAAmC,EAAE,IAVvC;MAWE,GAAG,EAAEzE;IAXP,EADF,CADF;EAiBD,CA/BD;;EAiCA,oBACE,6BAAC,kBAAD;IACE,aAAa,EAAC,OADhB;IAEE,WAAW,EAAE,KAFf;IAGE,OAAO,EAAED,MAHX;IAIE,cAAc,EAAE6E;EAJlB,GAMG7E,MAAM,GAAG+E,aAAa,EAAhB,GAAqB,IAN9B,CADF;AAUD,CA/PM;;;eAiQQhG,mB"}
@@ -25,9 +25,15 @@ const fetchCurrentLocation = async () => {
25
25
 
26
26
 
27
27
  const generateStartDataPayload = async (props, authToken, applicationConfiguration) => {
28
- var _props$theme, _props$theme$colors, _props$theme2, _props$theme2$appBar, _applicationConfigura, _applicationConfigura2, _applicationConfigura3, _props$config, _props$theme3, _props$theme3$appBar, _props$config2, _props$config2$appBar, _props$config3, _props$config3$addres, _props$config4, _props$config4$addres, _props$config5, _props$config5$addres, _props$config6, _props$config6$addres;
28
+ var _props$theme, _props$theme$colors, _props$theme2, _props$theme2$appBar, _applicationConfigura, _applicationConfigura2, _applicationConfigura3, _props$config, _props$theme3, _props$theme3$appBar, _props$config2, _props$config2$appBar, _props$config3, _props$config3$addres, _props$config4, _props$config4$addres, _props$config5, _props$config5$addres, _props$config6, _props$config6$addres, _props$config7;
29
29
 
30
30
  const payload = {};
31
+ const {
32
+ manufacturer,
33
+ model,
34
+ osVersion,
35
+ platform
36
+ } = await _OkHiNativeModule.OkHiNativeModule.retrieveDeviceInfo();
31
37
  payload.style = !props.theme ? undefined : {
32
38
  base: {
33
39
  color: (_props$theme = props.theme) === null || _props$theme === void 0 ? void 0 : (_props$theme$colors = _props$theme.colors) === null || _props$theme$colors === void 0 ? void 0 : _props$theme$colors.primary,
@@ -58,6 +64,12 @@ const generateStartDataPayload = async (props, authToken, applicationConfigurati
58
64
  },
59
65
  platform: {
60
66
  name: 'react-native'
67
+ },
68
+ device: {
69
+ manufacturer,
70
+ model,
71
+ platform,
72
+ osVersion
61
73
  }
62
74
  };
63
75
  payload.config = {
@@ -70,29 +82,27 @@ const generateStartDataPayload = async (props, authToken, applicationConfigurati
70
82
  home: typeof ((_props$config3 = props.config) === null || _props$config3 === void 0 ? void 0 : (_props$config3$addres = _props$config3.addressTypes) === null || _props$config3$addres === void 0 ? void 0 : _props$config3$addres.home) === 'boolean' ? (_props$config4 = props.config) === null || _props$config4 === void 0 ? void 0 : (_props$config4$addres = _props$config4.addressTypes) === null || _props$config4$addres === void 0 ? void 0 : _props$config4$addres.home : true,
71
83
  work: typeof ((_props$config5 = props.config) === null || _props$config5 === void 0 ? void 0 : (_props$config5$addres = _props$config5.addressTypes) === null || _props$config5$addres === void 0 ? void 0 : _props$config5$addres.work) === 'boolean' ? (_props$config6 = props.config) === null || _props$config6 === void 0 ? void 0 : (_props$config6$addres = _props$config6.addressTypes) === null || _props$config6$addres === void 0 ? void 0 : _props$config6$addres.work : true
72
84
  },
73
- protectedApps: _reactNative.Platform.OS === 'android' && (await (0, _OkCore.canOpenProtectedAppsSettings)())
85
+ protectedApps: _reactNative.Platform.OS === 'android' && (await (0, _OkCore.canOpenProtectedAppsSettings)()),
86
+ permissionsOnboarding: typeof ((_props$config7 = props.config) === null || _props$config7 === void 0 ? void 0 : _props$config7.permissionsOnboarding) === 'boolean' ? props.config.permissionsOnboarding : true
74
87
  };
75
88
 
76
89
  if (_reactNative.Platform.OS === 'ios') {
77
90
  const status = await _OkHiNativeModule.OkHiNativeModule.fetchIOSLocationPermissionStatus();
91
+ payload.context.permissions = {
92
+ location: status === 'authorizedWhenInUse' ? 'whenInUse' : status === 'authorizedAlways' || status === 'authorized' ? 'always' : 'denied'
93
+ };
78
94
 
79
- if (status !== 'notDetermined') {
80
- payload.context.permissions = {
81
- location: status === 'authorizedWhenInUse' ? 'whenInUse' : status === 'authorizedAlways' || status === 'authorized' ? 'always' : 'denided'
82
- };
83
-
84
- if (status === 'authorized' || status === 'authorizedWhenInUse' || status === 'authorizedAlways') {
85
- const location = await fetchCurrentLocation();
86
-
87
- if (location) {
88
- payload.context.coordinates = {
89
- currentLocation: {
90
- lat: location.lat,
91
- lng: location.lng,
92
- accuracy: location.accuracy
93
- }
94
- };
95
- }
95
+ if (status === 'authorized' || status === 'authorizedWhenInUse' || status === 'authorizedAlways') {
96
+ const location = await fetchCurrentLocation();
97
+
98
+ if (location) {
99
+ payload.context.coordinates = {
100
+ currentLocation: {
101
+ lat: location.lat,
102
+ lng: location.lng,
103
+ accuracy: location.accuracy
104
+ }
105
+ };
96
106
  }
97
107
  }
98
108
  } else if (_reactNative.Platform.OS === 'android') {
@@ -117,15 +127,6 @@ const generateStartDataPayload = async (props, authToken, applicationConfigurati
117
127
  location: hasBackgroundLocationPermission ? 'always' : hasLocationPermission ? 'whenInUse' : 'denied'
118
128
  };
119
129
  }
120
-
121
- const {
122
- manufacturer,
123
- model
124
- } = await _OkHiNativeModule.OkHiNativeModule.retrieveDeviceInfo();
125
- payload.context.device = {
126
- manufacturer,
127
- model
128
- };
129
130
  } else {
130
131
  throw new _OkCore.OkHiException({
131
132
  code: _OkCore.OkHiException.UNSUPPORTED_PLATFORM_CODE,
@@ -1 +1 @@
1
- {"version":3,"names":["fetchCurrentLocation","result","OkHiNativeModule","generateStartDataPayload","props","authToken","applicationConfiguration","payload","style","theme","undefined","base","color","colors","primary","logo","appBar","name","app","user","phone","firstName","lastName","email","auth","context","container","version","developer","library","manifest","platform","config","streetView","backgroundColor","visible","addressTypes","home","work","protectedApps","Platform","OS","canOpenProtectedAppsSettings","status","fetchIOSLocationPermissionStatus","permissions","location","coordinates","currentLocation","lat","lng","accuracy","hasLocationPermission","isLocationPermissionGranted","error","console","log","hasBackgroundLocationPermission","isBackgroundLocationPermissionGranted","manufacturer","model","retrieveDeviceInfo","device","OkHiException","code","UNSUPPORTED_PLATFORM_CODE","message","UNAUTHORIZED_MESSAGE","getFrameUrl","DEV_FRAME_URL","PROD_FRAME_URL","SANDBOX_FRAME_URL","LEGACY_DEV_FRAME_URL","LEGACY_PROD_FRAME_URL","LEGACY_SANDBOX_FRAME_URL","Version","mode","OkHiMode","PROD","generateJavaScriptStartScript","startPayload","jsBeforeLoad","JSON","stringify","jsAfterLoad","parseOkHiLocation","id","geo_point","lon","placeId","place_id","plusCode","plus_code","propertyName","property_name","streetName","street_name","title","subtitle","directions","otherInformation","other_information","url","streetViewPanoId","street_view","pano_id","streetViewPanoUrl","userId","user_id","propertyNumber","photo","displayTitle","display_title","country","state","city","countryCode","country_code"],"sources":["Util.ts"],"sourcesContent":["import type { OkHiLocationManagerProps } from './types';\nimport {\n canOpenProtectedAppsSettings,\n isBackgroundLocationPermissionGranted,\n isLocationPermissionGranted,\n OkHiException,\n OkHiLocation,\n} from '../OkCore';\nimport { OkHiMode } from '../OkCore';\nimport type {\n OkHiLocationManagerStartDataPayload,\n OkHiLocationManagerStartMessage,\n} from './types';\nimport manifest from './app.json'; //TODO: fix this\nimport type { AuthApplicationConfig } from '../OkCore/_types';\nimport { Platform } from 'react-native';\nimport { OkHiNativeModule } from '../OkHiNativeModule';\n\nconst fetchCurrentLocation = async (): Promise<null | {\n lat: number;\n lng: number;\n accuracy: number;\n}> => {\n const result = await OkHiNativeModule.fetchCurrentLocation();\n return result;\n};\n\n/**\n * @ignore\n */\nexport const generateStartDataPayload = async (\n props: OkHiLocationManagerProps,\n authToken: string,\n applicationConfiguration: AuthApplicationConfig\n): Promise<OkHiLocationManagerStartDataPayload> => {\n const payload: any = {};\n payload.style = !props.theme\n ? undefined\n : {\n base: {\n color: props.theme?.colors?.primary,\n logo: props.theme?.appBar?.logo,\n name: applicationConfiguration.app?.name,\n },\n };\n payload.user = {\n phone: props.user.phone,\n firstName: props.user.firstName,\n lastName: props.user.lastName,\n email: props.user.email,\n };\n payload.auth = {\n authToken,\n };\n payload.context = {\n container: {\n name: applicationConfiguration.app?.name,\n version: applicationConfiguration.app?.version,\n },\n developer: {\n name: applicationConfiguration.context.developer,\n },\n library: {\n name: manifest.name,\n version: manifest.version,\n },\n platform: {\n name: 'react-native',\n },\n };\n payload.config = {\n streetView:\n typeof props.config?.streetView === 'boolean'\n ? props.config.streetView\n : true,\n appBar: {\n color: props.theme?.appBar?.backgroundColor,\n visible: props.config?.appBar?.visible,\n },\n addressTypes: {\n home:\n typeof props.config?.addressTypes?.home === 'boolean'\n ? props.config?.addressTypes?.home\n : true,\n work:\n typeof props.config?.addressTypes?.work === 'boolean'\n ? props.config?.addressTypes?.work\n : true,\n },\n protectedApps:\n Platform.OS === 'android' && (await canOpenProtectedAppsSettings()),\n };\n\n if (Platform.OS === 'ios') {\n const status = await OkHiNativeModule.fetchIOSLocationPermissionStatus();\n if (status !== 'notDetermined') {\n payload.context.permissions = {\n location:\n status === 'authorizedWhenInUse'\n ? 'whenInUse'\n : status === 'authorizedAlways' || status === 'authorized'\n ? 'always'\n : 'denided',\n };\n if (\n status === 'authorized' ||\n status === 'authorizedWhenInUse' ||\n status === 'authorizedAlways'\n ) {\n const location = await fetchCurrentLocation();\n if (location) {\n payload.context.coordinates = {\n currentLocation: {\n lat: location.lat,\n lng: location.lng,\n accuracy: location.accuracy,\n },\n };\n }\n }\n }\n } else if (Platform.OS === 'android') {\n let hasLocationPermission: boolean | undefined;\n try {\n hasLocationPermission = await isLocationPermissionGranted();\n } catch (error) {\n console.log(error);\n }\n\n let hasBackgroundLocationPermission: boolean | undefined;\n try {\n hasBackgroundLocationPermission =\n await isBackgroundLocationPermissionGranted();\n } catch (error) {\n console.log(error);\n }\n\n if (\n typeof hasLocationPermission === 'boolean' &&\n typeof hasBackgroundLocationPermission === 'boolean'\n ) {\n payload.context.permissions = {\n location: hasBackgroundLocationPermission\n ? 'always'\n : hasLocationPermission\n ? 'whenInUse'\n : 'denied',\n };\n }\n const { manufacturer, model } = await OkHiNativeModule.retrieveDeviceInfo();\n payload.context.device = {\n manufacturer,\n model,\n };\n } else {\n throw new OkHiException({\n code: OkHiException.UNSUPPORTED_PLATFORM_CODE,\n message: OkHiException.UNAUTHORIZED_MESSAGE,\n });\n }\n return payload;\n};\n\n/**\n * @ignore\n */\nexport const getFrameUrl = (\n applicationConfiguration: AuthApplicationConfig\n): string => {\n const DEV_FRAME_URL = 'https://dev-manager-v5.okhi.io';\n const PROD_FRAME_URL = 'https://manager-v5.okhi.io';\n const SANDBOX_FRAME_URL = 'https://sandbox-manager-v5.okhi.io';\n\n const LEGACY_DEV_FRAME_URL = 'https://dev-legacy-manager-v5.okhi.io';\n const LEGACY_PROD_FRAME_URL = 'https://legacy-manager-v5.okhi.io';\n const LEGACY_SANDBOX_FRAME_URL = 'https://sandbox-legacy-manager-v5.okhi.io';\n\n if (Platform.OS === 'android' && Platform.Version < 24) {\n if (applicationConfiguration.context.mode === OkHiMode.PROD) {\n return LEGACY_PROD_FRAME_URL;\n }\n if (applicationConfiguration.context.mode === ('dev' as any)) {\n return LEGACY_DEV_FRAME_URL;\n }\n return LEGACY_SANDBOX_FRAME_URL;\n }\n if (applicationConfiguration.context.mode === OkHiMode.PROD) {\n return PROD_FRAME_URL;\n }\n if (applicationConfiguration.context.mode === ('dev' as any)) {\n return DEV_FRAME_URL;\n }\n return SANDBOX_FRAME_URL;\n};\n\n/**\n * @ignore\n */\nexport const generateJavaScriptStartScript = (startPayload: {\n message: OkHiLocationManagerStartMessage;\n payload: OkHiLocationManagerStartDataPayload;\n}) => {\n const jsBeforeLoad = `\n window.isNativeApp = true;\n window.NativeApp = {\n bridge: {\n receiveMessage: window.ReactNativeWebView.postMessage\n },\n data: ${JSON.stringify(startPayload)}\n }\n true;\n `;\n const jsAfterLoad = `window.startOkHiLocationManager({ receiveMessage: function(data) { window.ReactNativeWebView.postMessage(data) } }, ${JSON.stringify(\n startPayload\n )})`;\n return { jsBeforeLoad, jsAfterLoad };\n};\n\n/**\n * @ignore\n */\nexport const parseOkHiLocation = (location: any): OkHiLocation => {\n return {\n id: location?.id,\n lat: location?.geo_point?.lat,\n lon: location?.geo_point?.lon,\n placeId: location?.place_id,\n plusCode: location?.plus_code,\n propertyName: location?.property_name,\n streetName: location?.street_name,\n title: location?.title,\n subtitle: location?.subtitle,\n directions: location?.directions,\n otherInformation: location?.other_information,\n url: location?.url,\n streetViewPanoId: location?.street_view?.pano_id,\n streetViewPanoUrl: location?.street_view?.url,\n userId: location?.user_id,\n propertyNumber: location?.propertyNumber,\n photo: location?.photo,\n displayTitle: location?.display_title,\n country: location?.country,\n state: location?.state,\n city: location?.city,\n countryCode: location?.country_code,\n };\n};\n"],"mappings":";;;;;;;AACA;;AAYA;;AAEA;;AACA;;;;AAEA,MAAMA,oBAAoB,GAAG,YAIvB;EACJ,MAAMC,MAAM,GAAG,MAAMC,kCAAA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AZ,2DAAE,uBAAuBF,GAdrC;IAeLK,MAAM,EAAE7D,QAAF,aAAEA,QAAF,uBAAEA,QAAQ,CAAE8D,OAfb;IAgBLC,cAAc,EAAE/D,QAAF,aAAEA,QAAF,uBAAEA,QAAQ,CAAE+D,cAhBrB;IAiBLC,KAAK,EAAEhE,QAAF,aAAEA,QAAF,uBAAEA,QAAQ,CAAEgE,KAjBZ;IAkBLC,YAAY,EAAEjE,QAAF,aAAEA,QAAF,uBAAEA,QAAQ,CAAEkE,aAlBnB;IAmBLC,OAAO,EAAEnE,QAAF,aAAEA,QAAF,uBAAEA,QAAQ,CAAEmE,OAnBd;IAoBLC,KAAK,EAAEpE,QAAF,aAAEA,QAAF,uBAAEA,QAAQ,CAAEoE,KApBZ;IAqBLC,IAAI,EAAErE,QAAF,aAAEA,QAAF,uBAAEA,QAAQ,CAAEqE,IArBX;IAsBLC,WAAW,EAAEtE,QAAF,aAAEA,QAAF,uBAAEA,QAAQ,CAAEuE;EAtBlB,CAAP;AAwBD,CAzBM"}
1
+ {"version":3,"names":["fetchCurrentLocation","result","OkHiNativeModule","generateStartDataPayload","props","authToken","applicationConfiguration","payload","manufacturer","model","osVersion","platform","retrieveDeviceInfo","style","theme","undefined","base","color","colors","primary","logo","appBar","name","app","user","phone","firstName","lastName","email","auth","context","container","version","developer","library","manifest","device","config","streetView","backgroundColor","visible","addressTypes","home","work","protectedApps","Platform","OS","canOpenProtectedAppsSettings","permissionsOnboarding","status","fetchIOSLocationPermissionStatus","permissions","location","coordinates","currentLocation","lat","lng","accuracy","hasLocationPermission","isLocationPermissionGranted","error","console","log","hasBackgroundLocationPermission","isBackgroundLocationPermissionGranted","OkHiException","code","UNSUPPORTED_PLATFORM_CODE","message","UNAUTHORIZED_MESSAGE","getFrameUrl","DEV_FRAME_URL","PROD_FRAME_URL","SANDBOX_FRAME_URL","LEGACY_DEV_FRAME_URL","LEGACY_PROD_FRAME_URL","LEGACY_SANDBOX_FRAME_URL","Version","mode","OkHiMode","PROD","generateJavaScriptStartScript","startPayload","jsBeforeLoad","JSON","stringify","jsAfterLoad","parseOkHiLocation","id","geo_point","lon","placeId","place_id","plusCode","plus_code","propertyName","property_name","streetName","street_name","title","subtitle","directions","otherInformation","other_information","url","streetViewPanoId","street_view","pano_id","streetViewPanoUrl","userId","user_id","propertyNumber","photo","displayTitle","display_title","country","state","city","countryCode","country_code"],"sources":["Util.ts"],"sourcesContent":["import type { OkHiLocationManagerProps } from './types';\nimport {\n canOpenProtectedAppsSettings,\n isBackgroundLocationPermissionGranted,\n isLocationPermissionGranted,\n OkHiException,\n OkHiLocation,\n} from '../OkCore';\nimport { OkHiMode } from '../OkCore';\nimport type {\n OkHiLocationManagerStartDataPayload,\n OkHiLocationManagerStartMessage,\n} from './types';\nimport manifest from './app.json'; //TODO: fix this\nimport type { AuthApplicationConfig } from '../OkCore/_types';\nimport { Platform } from 'react-native';\nimport { OkHiNativeModule } from '../OkHiNativeModule';\n\nconst fetchCurrentLocation = async (): Promise<null | {\n lat: number;\n lng: number;\n accuracy: number;\n}> => {\n const result = await OkHiNativeModule.fetchCurrentLocation();\n return result;\n};\n\n/**\n * @ignore\n */\nexport const generateStartDataPayload = async (\n props: OkHiLocationManagerProps,\n authToken: string,\n applicationConfiguration: AuthApplicationConfig\n): Promise<OkHiLocationManagerStartDataPayload> => {\n const payload: any = {};\n const { manufacturer, model, osVersion, platform } =\n await OkHiNativeModule.retrieveDeviceInfo();\n payload.style = !props.theme\n ? undefined\n : {\n base: {\n color: props.theme?.colors?.primary,\n logo: props.theme?.appBar?.logo,\n name: applicationConfiguration.app?.name,\n },\n };\n payload.user = {\n phone: props.user.phone,\n firstName: props.user.firstName,\n lastName: props.user.lastName,\n email: props.user.email,\n };\n payload.auth = {\n authToken,\n };\n payload.context = {\n container: {\n name: applicationConfiguration.app?.name,\n version: applicationConfiguration.app?.version,\n },\n developer: {\n name: applicationConfiguration.context.developer,\n },\n library: {\n name: manifest.name,\n version: manifest.version,\n },\n platform: {\n name: 'react-native',\n },\n device: {\n manufacturer,\n model,\n platform,\n osVersion,\n },\n };\n payload.config = {\n streetView:\n typeof props.config?.streetView === 'boolean'\n ? props.config.streetView\n : true,\n appBar: {\n color: props.theme?.appBar?.backgroundColor,\n visible: props.config?.appBar?.visible,\n },\n addressTypes: {\n home:\n typeof props.config?.addressTypes?.home === 'boolean'\n ? props.config?.addressTypes?.home\n : true,\n work:\n typeof props.config?.addressTypes?.work === 'boolean'\n ? props.config?.addressTypes?.work\n : true,\n },\n protectedApps:\n Platform.OS === 'android' && (await canOpenProtectedAppsSettings()),\n permissionsOnboarding:\n typeof props.config?.permissionsOnboarding === 'boolean'\n ? props.config.permissionsOnboarding\n : true,\n };\n\n if (Platform.OS === 'ios') {\n const status = await OkHiNativeModule.fetchIOSLocationPermissionStatus();\n payload.context.permissions = {\n location:\n status === 'authorizedWhenInUse'\n ? 'whenInUse'\n : status === 'authorizedAlways' || status === 'authorized'\n ? 'always'\n : 'denied',\n };\n if (\n status === 'authorized' ||\n status === 'authorizedWhenInUse' ||\n status === 'authorizedAlways'\n ) {\n const location = await fetchCurrentLocation();\n if (location) {\n payload.context.coordinates = {\n currentLocation: {\n lat: location.lat,\n lng: location.lng,\n accuracy: location.accuracy,\n },\n };\n }\n }\n } else if (Platform.OS === 'android') {\n let hasLocationPermission: boolean | undefined;\n try {\n hasLocationPermission = await isLocationPermissionGranted();\n } catch (error) {\n console.log(error);\n }\n\n let hasBackgroundLocationPermission: boolean | undefined;\n try {\n hasBackgroundLocationPermission =\n await isBackgroundLocationPermissionGranted();\n } catch (error) {\n console.log(error);\n }\n\n if (\n typeof hasLocationPermission === 'boolean' &&\n typeof hasBackgroundLocationPermission === 'boolean'\n ) {\n payload.context.permissions = {\n location: hasBackgroundLocationPermission\n ? 'always'\n : hasLocationPermission\n ? 'whenInUse'\n : 'denied',\n };\n }\n } else {\n throw new OkHiException({\n code: OkHiException.UNSUPPORTED_PLATFORM_CODE,\n message: OkHiException.UNAUTHORIZED_MESSAGE,\n });\n }\n return payload;\n};\n\n/**\n * @ignore\n */\nexport const getFrameUrl = (\n applicationConfiguration: AuthApplicationConfig\n): string => {\n const DEV_FRAME_URL = 'https://dev-manager-v5.okhi.io';\n const PROD_FRAME_URL = 'https://manager-v5.okhi.io';\n const SANDBOX_FRAME_URL = 'https://sandbox-manager-v5.okhi.io';\n\n const LEGACY_DEV_FRAME_URL = 'https://dev-legacy-manager-v5.okhi.io';\n const LEGACY_PROD_FRAME_URL = 'https://legacy-manager-v5.okhi.io';\n const LEGACY_SANDBOX_FRAME_URL = 'https://sandbox-legacy-manager-v5.okhi.io';\n\n if (Platform.OS === 'android' && Platform.Version < 24) {\n if (applicationConfiguration.context.mode === OkHiMode.PROD) {\n return LEGACY_PROD_FRAME_URL;\n }\n if (applicationConfiguration.context.mode === ('dev' as any)) {\n return LEGACY_DEV_FRAME_URL;\n }\n return LEGACY_SANDBOX_FRAME_URL;\n }\n if (applicationConfiguration.context.mode === OkHiMode.PROD) {\n return PROD_FRAME_URL;\n }\n if (applicationConfiguration.context.mode === ('dev' as any)) {\n return DEV_FRAME_URL;\n }\n return SANDBOX_FRAME_URL;\n};\n\n/**\n * @ignore\n */\nexport const generateJavaScriptStartScript = (startPayload: {\n message: OkHiLocationManagerStartMessage;\n payload: OkHiLocationManagerStartDataPayload;\n}) => {\n const jsBeforeLoad = `\n window.isNativeApp = true;\n window.NativeApp = {\n bridge: {\n receiveMessage: window.ReactNativeWebView.postMessage\n },\n data: ${JSON.stringify(startPayload)}\n }\n true;\n `;\n const jsAfterLoad = `window.startOkHiLocationManager({ receiveMessage: function(data) { window.ReactNativeWebView.postMessage(data) } }, ${JSON.stringify(\n startPayload\n )})`;\n return { jsBeforeLoad, jsAfterLoad };\n};\n\n/**\n * @ignore\n */\nexport const parseOkHiLocation = (location: any): OkHiLocation => {\n return {\n id: location?.id,\n lat: location?.geo_point?.lat,\n lon: location?.geo_point?.lon,\n placeId: location?.place_id,\n plusCode: location?.plus_code,\n propertyName: location?.property_name,\n streetName: location?.street_name,\n title: location?.title,\n subtitle: location?.subtitle,\n directions: location?.directions,\n otherInformation: location?.other_information,\n url: location?.url,\n streetViewPanoId: location?.street_view?.pano_id,\n streetViewPanoUrl: location?.street_view?.url,\n userId: location?.user_id,\n propertyNumber: location?.propertyNumber,\n photo: location?.photo,\n displayTitle: location?.display_title,\n country: location?.country,\n state: location?.state,\n city: location?.city,\n countryCode: location?.country_code,\n };\n};\n"],"mappings":";;;;;;;AACA;;AAYA;;AAEA;;AACA;;;;AAEA,MAAMA,oBAAoB,GAAG,YAIvB;EACJ,MAAMC,MAAM,GAAG,MAAMC,kCAAA,CAAiBF,oBAAjB,EAArB;EACA,OAAOC,MAAP;AACD,CAPD;AASA;AACA;AACA;;;AACO,MAAME,wBAAwB,GAAG,OACtCC,KADsC,EAEtCC,SAFsC,EAGtCC,wBAHsC,KAIW;EAAA;;EACjD,MAAMC,OAAY,GAAG,EAArB;EACA,MAAM;IAAEC,YAAF;IAAgBC,KAAhB;IAAuBC,SAAvB;IAAkCC;EAAlC,IACJ,MAAMT,kCAAA,CAAiBU,kBAAjB,EADR;EAEAL,OAAO,CAACM,KAAR,GAAgB,CAACT,KAAK,CAACU,KAAP,GACZC,SADY,GAEZ;IACEC,IAAI,EAAE;MACJC,KAAK,kBAAEb,KAAK,CAACU,KAAR,wEAAE,aAAaI,MAAf,wDAAE,oBAAqBC,OADxB;MAEJC,IAAI,mBAAEhB,KAAK,CAACU,KAAR,0EAAE,cAAaO,MAAf,yDAAE,qBAAqBD,IAFvB;MAGJE,IAAI,2BAAEhB,wBAAwB,CAACiB,GAA3B,0DAAE,sBAA8BD;IAHhC;EADR,CAFJ;EASAf,OAAO,CAACiB,IAAR,GAAe;IACbC,KAAK,EAAErB,KAAK,CAACoB,IAAN,CAAWC,KADL;IAEbC,SAAS,EAAEtB,KAAK,CAACoB,IAAN,CAAWE,SAFT;IAGbC,QAAQ,EAAEvB,KAAK,CAACoB,IAAN,CAAWG,QAHR;IAI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version": "1.2.3-beta.2"
4
4
  }
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { ViewStyle } from 'react-native';\nimport type { OkHiException } from '../OkCore/OkHiException';\nimport type { OkHiUser, OkHiLocation } from '../OkCore/types';\nimport type { OkVerifyStartConfiguration } from '../OkVerify/types';\n\n/**\n * The OkCollect Success Response object contains information about the newly created user and location once an address has been successfully created.\n * It can be used to extract information about the address and/or start address verification process.\n */\nexport interface OkCollectSuccessResponse {\n /**\n * The [OkHiUser](https://okhi.github.io/react-native-core/interfaces/okhiuser.html) object containing information about the newly created user.\n */\n user: OkHiUser;\n /**\n * The [OkHiLocation](https://okhi.github.io/react-native-core/interfaces/okhilocation.html) object containing information about the newly created user.\n */\n location: OkHiLocation;\n\n /**\n * Starts address verification\n */\n startVerification: (config?: OkVerifyStartConfiguration) => Promise<string>;\n}\n\n/**\n * The OkHiLocationManager exposes props that you can use to customise it's functionality and appearance.\n */\nexport interface OkHiLocationManagerProps {\n /**\n * **Required:** A boolean flag that determines whether or not to show the Location Manager.\n */\n launch: boolean;\n /**\n * **Required:** A defined [OkHiUser](https://okhi.github.io/react-native-core/interfaces/okhiuser.html) object, with a mandatory \"phone\" key property.\n */\n user: OkHiUser;\n /**\n * **Optional:** A custom JSX.Element that'll be used as a loading indicator.\n */\n loader?: JSX.Element;\n /**\n * **Optional:** Used to customise the appearance of the Container that wraps the location manager.\n */\n style?: ViewStyle;\n /**\n * **Required:** A callback that'll be invoked with an {@link OkCollectSuccessResponse} once an accurate OkHi address has been successfully created.\n */\n onSuccess: (response: OkCollectSuccessResponse) => any;\n /**\n * **Required:** A callback that'll be invoked whenever an error occurs during the address creation process.\n */\n onError: (error: OkHiException) => any;\n /**\n * **Required:** A callback that'll be invoked whenever a user taps on the close button.\n */\n onCloseRequest: () => any;\n /**\n * **Optional:** An object that'll be used to customise the appearance of the Location Manager to better match your branding requirements.\n */\n theme?: {\n appBar?: {\n backgroundColor?: string;\n logo?: string;\n };\n colors?: {\n primary?: string;\n };\n };\n /**\n * **Optional:** An object that'll be used to customise the functionality of the Location Manager. This object dictates whether you want some features on or off.\n */\n config?: {\n streetView?: boolean;\n appBar?: {\n visible?: boolean;\n };\n addressTypes?: {\n home?: boolean;\n work?: boolean;\n };\n };\n\n /**\n * **Optional:** Enable a user to either select an existing address, or force to create a new one\n */\n mode?: 'create' | 'select';\n}\n\n/**\n * @ignore\n */\nexport interface OkHiLocationManagerStartDataPayload {\n style?: {\n base?: {\n color?: string;\n logo?: string;\n name?: string;\n };\n };\n auth: {\n authToken: string;\n };\n context: {\n container?: {\n name?: string;\n version?: string;\n };\n developer: {\n name: string;\n };\n library: {\n name: string;\n version: string;\n };\n platform: {\n name: 'react-native';\n };\n };\n config?: {\n streetView?: boolean;\n appBar?: {\n color?: string;\n visible?: boolean;\n };\n };\n user: OkHiUser;\n}\n\n/**\n * @ignore\n */\nexport type OkHiLocationManagerStartMessage = 'select_location' | 'start_app';\n\n/**\n * @ignore\n */\nexport interface OkHiLocationManagerResponse {\n message:\n | 'location_selected'\n | 'location_created'\n | 'location_updated'\n | 'exit_app'\n | 'request_enable_protected_apps'\n | 'fatal_exit';\n payload: { user: any; location: any };\n}\n"],"mappings":""}
1
+ {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { ViewStyle } from 'react-native';\nimport type { OkHiException } from '../OkCore/OkHiException';\nimport type { OkHiUser, OkHiLocation } from '../OkCore/types';\nimport type { OkVerifyStartConfiguration } from '../OkVerify/types';\n\n/**\n * The OkCollect Success Response object contains information about the newly created user and location once an address has been successfully created.\n * It can be used to extract information about the address and/or start address verification process.\n */\nexport interface OkCollectSuccessResponse {\n /**\n * The [OkHiUser](https://okhi.github.io/react-native-core/interfaces/okhiuser.html) object containing information about the newly created user.\n */\n user: OkHiUser;\n /**\n * The [OkHiLocation](https://okhi.github.io/react-native-core/interfaces/okhilocation.html) object containing information about the newly created user.\n */\n location: OkHiLocation;\n\n /**\n * Starts address verification\n */\n startVerification: (config?: OkVerifyStartConfiguration) => Promise<string>;\n}\n\n/**\n * The OkHiLocationManager exposes props that you can use to customise it's functionality and appearance.\n */\nexport interface OkHiLocationManagerProps {\n /**\n * **Required:** A boolean flag that determines whether or not to show the Location Manager.\n */\n launch: boolean;\n /**\n * **Required:** A defined [OkHiUser](https://okhi.github.io/react-native-core/interfaces/okhiuser.html) object, with a mandatory \"phone\" key property.\n */\n user: OkHiUser;\n /**\n * **Optional:** A custom JSX.Element that'll be used as a loading indicator.\n */\n loader?: JSX.Element;\n /**\n * **Optional:** Used to customise the appearance of the Container that wraps the location manager.\n */\n style?: ViewStyle;\n /**\n * **Required:** A callback that'll be invoked with an {@link OkCollectSuccessResponse} once an accurate OkHi address has been successfully created.\n */\n onSuccess: (response: OkCollectSuccessResponse) => any;\n /**\n * **Required:** A callback that'll be invoked whenever an error occurs during the address creation process.\n */\n onError: (error: OkHiException) => any;\n /**\n * **Required:** A callback that'll be invoked whenever a user taps on the close button.\n */\n onCloseRequest: () => any;\n /**\n * **Optional:** An object that'll be used to customise the appearance of the Location Manager to better match your branding requirements.\n */\n theme?: {\n appBar?: {\n backgroundColor?: string;\n logo?: string;\n };\n colors?: {\n primary?: string;\n };\n };\n /**\n * **Optional:** An object that'll be used to customise the functionality of the Location Manager. This object dictates whether you want some features on or off.\n */\n config?: {\n streetView?: boolean;\n appBar?: {\n visible?: boolean;\n };\n addressTypes?: {\n home?: boolean;\n work?: boolean;\n };\n permissionsOnboarding?: boolean;\n };\n\n /**\n * **Optional:** Enable a user to either select an existing address, or force to create a new one\n */\n mode?: 'create' | 'select';\n}\n\n/**\n * @ignore\n */\nexport interface OkHiLocationManagerStartDataPayload {\n style?: {\n base?: {\n color?: string;\n logo?: string;\n name?: string;\n };\n };\n auth: {\n authToken: string;\n };\n context: {\n container?: {\n name?: string;\n version?: string;\n };\n developer: {\n name: string;\n };\n library: {\n name: string;\n version: string;\n };\n platform: {\n name: 'react-native';\n };\n };\n config?: {\n streetView?: boolean;\n appBar?: {\n color?: string;\n visible?: boolean;\n };\n };\n user: OkHiUser;\n}\n\n/**\n * @ignore\n */\nexport type OkHiLocationManagerStartMessage = 'select_location' | 'start_app';\n\n/**\n * @ignore\n */\nexport interface OkHiLocationManagerResponse {\n message:\n | 'location_selected'\n | 'location_created'\n | 'location_updated'\n | 'exit_app'\n | 'request_enable_protected_apps'\n | 'fatal_exit'\n | 'request_location_permission';\n payload: any;\n}\n"],"mappings":""}
@@ -1,2 +1,6 @@
1
1
  "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
2
6
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["/**\n * Defines the structure of the user object requried by OkHi services and libraries.\n */\nexport interface OkHiUser {\n /**\n * The user's phone number. Must be MSISDN standard format. e.g +254712345678.\n */\n phone: string;\n /**\n * The user's first name.\n */\n firstName?: string;\n /**\n * The user's last name.\n */\n lastName?: string;\n /**\n * The user's email address.\n */\n email?: string;\n /**\n * The OkHi's userId. Usually obtained after a user successfully creates an OkHi address.\n */\n id?: string;\n\n /**\n * The user's device firebase push notification token.\n */\n fcmPushNotificationToken?: string;\n}\n\n/**\n * Defines the current mode you'll be using OkHi's services as well as your application's meta information.\n */\nexport interface OkHiAppContext {\n /**\n * The current mode you'll be using OkHi services.\n */\n mode: 'sandbox' | 'prod' | string;\n /**\n * Your application's meta information.\n */\n app?: {\n /**\n * Your application's name.\n */\n name: string;\n /**\n * Your application's current version.\n */\n version: string;\n /**\n * Your application's current build number.\n */\n build: number;\n };\n /**\n * Meta information about the current developer.\n */\n developer?: string;\n}\n\n/**\n * Defines the structure of the OkHi location object once an address has been successfully created by the user.\n */\nexport interface OkHiLocation {\n /**\n * The latitude of the location.\n */\n lat: number;\n /**\n * The longitude of the location.\n */\n lon: number;\n /**\n * The OkHi's locationId. Usually obtained once an address has been successfully created by the user.\n */\n id?: string;\n /**\n * The id of a common residential or geological space such as apartment building or office block.\n */\n placeId?: string;\n /**\n * Geocode system for identifying an area anywhere on the Earth.\n * See https://plus.codes/\n */\n plusCode?: string;\n /**\n * The location's property name.\n */\n propertyName?: string;\n /**\n * The location's street name.\n */\n streetName?: string;\n /**\n * A string that can be used to render information about the location.\n */\n title?: string;\n /**\n * A string that can be used to render meta information about the location.\n */\n subtitle?: string;\n /**\n * User generated directions to the location.\n */\n directions?: string;\n /**\n * User generated meta information about the location, how to access it and any other relevant notes.\n */\n otherInformation?: string;\n /**\n * A link to the user's address visible on browser or desktop.\n */\n url?: string;\n /**\n * A Google's StreetView Panorama Id, if the address was created using Google StreetView.\n * See: https://developers.google.com/maps/documentation/javascript/streetview\n */\n streetViewPanoId?: string;\n /**\n * A Google's StreetView Panorama Url, if the address was created using Google StreetView.\n * See: https://developers.google.com/maps/documentation/javascript/streetview\n */\n streetViewPanoUrl?: string;\n /**\n * The OkHi's userId. Usually obtained after a user successfully creates an OkHi address.\n */\n userId?: string;\n /**\n * The location's property number.\n */\n propertyNumber?: string;\n /**\n * A link to the location's gate photo.\n */\n photo?: string;\n\n /**\n * A user's country\n */\n country?: string;\n\n /**\n * A user's city\n */\n city?: string;\n\n /**\n * A user's state\n */\n state?: string;\n\n /**\n * A formatted location information\n */\n displayTitle?: string;\n\n /**\n * A user's country code\n */\n countryCode?: string;\n}\n\n/**\n * @ignore\n */\nexport interface OkHiError {\n code: string;\n message: string;\n}\n\nexport type OkHiApplicationConfiguration = {\n credentials: {\n branchId: string;\n clientKey: string;\n };\n context: {\n mode: 'sandbox' | 'prod';\n developer?: 'okhi' | 'external';\n };\n app?: {\n name?: string;\n version?: string;\n build?: string;\n };\n notification?: {\n title: string;\n text: string;\n channelId: string;\n channelName: string;\n channelDescription: string;\n };\n};\n\nexport type LocationPermissionStatus =\n | 'notDetermined'\n | 'restricted'\n | 'denied'\n | 'authorizedAlways'\n | 'authorizedWhenInUse'\n | 'authorized'\n | 'unknown';\n\nexport type LocationPermissionStatusCallback =\n | LocationPermissionStatus\n | 'rationaleDissmissed';\nexport type LocationRequestPermissionType = 'whenInUse' | 'always';\n\nexport type LocationPermissionCallback = (\n status: LocationPermissionStatusCallback | null,\n error: OkHiError | null\n) => any;\n"],"mappings":""}
1
+ {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { OkHiException } from './OkHiException';\n\n/**\n * Defines the structure of the user object requried by OkHi services and libraries.\n */\nexport interface OkHiUser {\n /**\n * The user's phone number. Must be MSISDN standard format. e.g +254712345678.\n */\n phone: string;\n /**\n * The user's first name.\n */\n firstName?: string;\n /**\n * The user's last name.\n */\n lastName?: string;\n /**\n * The user's email address.\n */\n email?: string;\n /**\n * The OkHi's userId. Usually obtained after a user successfully creates an OkHi address.\n */\n id?: string;\n\n /**\n * The user's device firebase push notification token.\n */\n fcmPushNotificationToken?: string;\n}\n\n/**\n * Defines the current mode you'll be using OkHi's services as well as your application's meta information.\n */\nexport interface OkHiAppContext {\n /**\n * The current mode you'll be using OkHi services.\n */\n mode: 'sandbox' | 'prod' | string;\n /**\n * Your application's meta information.\n */\n app?: {\n /**\n * Your application's name.\n */\n name: string;\n /**\n * Your application's current version.\n */\n version: string;\n /**\n * Your application's current build number.\n */\n build: number;\n };\n /**\n * Meta information about the current developer.\n */\n developer?: string;\n}\n\n/**\n * Defines the structure of the OkHi location object once an address has been successfully created by the user.\n */\nexport interface OkHiLocation {\n /**\n * The latitude of the location.\n */\n lat: number;\n /**\n * The longitude of the location.\n */\n lon: number;\n /**\n * The OkHi's locationId. Usually obtained once an address has been successfully created by the user.\n */\n id?: string;\n /**\n * The id of a common residential or geological space such as apartment building or office block.\n */\n placeId?: string;\n /**\n * Geocode system for identifying an area anywhere on the Earth.\n * See https://plus.codes/\n */\n plusCode?: string;\n /**\n * The location's property name.\n */\n propertyName?: string;\n /**\n * The location's street name.\n */\n streetName?: string;\n /**\n * A string that can be used to render information about the location.\n */\n title?: string;\n /**\n * A string that can be used to render meta information about the location.\n */\n subtitle?: string;\n /**\n * User generated directions to the location.\n */\n directions?: string;\n /**\n * User generated meta information about the location, how to access it and any other relevant notes.\n */\n otherInformation?: string;\n /**\n * A link to the user's address visible on browser or desktop.\n */\n url?: string;\n /**\n * A Google's StreetView Panorama Id, if the address was created using Google StreetView.\n * See: https://developers.google.com/maps/documentation/javascript/streetview\n */\n streetViewPanoId?: string;\n /**\n * A Google's StreetView Panorama Url, if the address was created using Google StreetView.\n * See: https://developers.google.com/maps/documentation/javascript/streetview\n */\n streetViewPanoUrl?: string;\n /**\n * The OkHi's userId. Usually obtained after a user successfully creates an OkHi address.\n */\n userId?: string;\n /**\n * The location's property number.\n */\n propertyNumber?: string;\n /**\n * A link to the location's gate photo.\n */\n photo?: string;\n\n /**\n * A user's country\n */\n country?: string;\n\n /**\n * A user's city\n */\n city?: string;\n\n /**\n * A user's state\n */\n state?: string;\n\n /**\n * A formatted location information\n */\n displayTitle?: string;\n\n /**\n * A user's country code\n */\n countryCode?: string;\n}\n\n/**\n * @ignore\n */\nexport interface OkHiError {\n code: string;\n message: string;\n}\n\nexport type OkHiApplicationConfiguration = {\n credentials: {\n branchId: string;\n clientKey: string;\n };\n context: {\n mode: 'sandbox' | 'prod';\n developer?: 'okhi' | 'external';\n };\n app?: {\n name?: string;\n version?: string;\n build?: string;\n };\n notification?: {\n title: string;\n text: string;\n channelId: string;\n channelName: string;\n channelDescription: string;\n };\n};\n\nexport type LocationPermissionStatus =\n | 'notDetermined'\n | 'restricted'\n | 'denied'\n | 'authorizedAlways'\n | 'authorizedWhenInUse'\n | 'authorized'\n | 'unknown';\n\nexport type LocationPermissionStatusCallback =\n | LocationPermissionStatus\n | 'rationaleDissmissed';\nexport type LocationRequestPermissionType = 'whenInUse' | 'always';\n\nexport type LocationPermissionCallback = (\n status: LocationPermissionStatusCallback | null,\n error: OkHiException | null\n) => any;\n"],"mappings":""}
@@ -1 +1 @@
1
- {"version":3,"names":["LINKING_ERROR","Platform","select","ios","default","OkHiNativeModule","NativeModules","Okhi","Proxy","get","Error","OkHiNativeEvents","NativeEventEmitter","addListener"],"sources":["index.ts"],"sourcesContent":["import { NativeModules, NativeEventEmitter, Platform } from 'react-native';\nimport type { OkVerifyStartConfiguration } from '../OkVerify/types';\n\nconst LINKING_ERROR =\n `The package 'react-native-okhi' doesn't seem to be linked. Make sure: \\n\\n` +\n Platform.select({ ios: \"- You have run 'pod install'\\n\", default: '' }) +\n '- You rebuilt the app after installing the package\\n' +\n '- You are not using Expo managed workflow\\n';\n\ntype OkHiNativeModuleType = {\n isLocationServicesEnabled(): Promise<boolean>;\n isLocationPermissionGranted(): Promise<boolean>;\n isBackgroundLocationPermissionGranted(): Promise<boolean>;\n requestLocationPermission(): Promise<boolean>;\n requestBackgroundLocationPermission(): Promise<boolean>;\n requestEnableLocationServices(): Promise<boolean>;\n isGooglePlayServicesAvailable(): Promise<boolean>;\n requestEnableGooglePlayServices(): Promise<boolean>;\n getSystemVersion(): Promise<number | string>;\n getAuthToken(branchId: string, clientKey: string): Promise<string>;\n initialize(configuration: string): Promise<void>;\n startAddressVerification(\n phoneNumber: string,\n locationId: string,\n lat: Number,\n lon: Number,\n configuration?: OkVerifyStartConfiguration,\n fcmPushNotificationToken?: string\n ): Promise<string>;\n stopAddressVerification(\n phoneNumber: string,\n locationId: string\n ): Promise<string>;\n startForegroundService(): Promise<boolean>;\n stopForegroundService(): Promise<boolean>;\n isForegroundServiceRunning(): Promise<boolean>;\n initializeIOS(\n branchId: string,\n clientKey: string,\n environment: string\n ): Promise<boolean>;\n openAppSettings(): Promise<void>;\n retriveLocationPermissionStatus(): Promise<string>;\n requestTrackingAuthorization(): Promise<string | null>;\n canOpenProtectedAppsSettings(): Promise<boolean>;\n openProtectedAppsSettings(): Promise<boolean>;\n retrieveDeviceInfo(): Promise<{ manufacturer: string; model: string }>;\n setItem(key: string, value: string): Promise<boolean>;\n onNewToken(fcmPushNotificationToken: string): Promise<boolean>;\n onMessageReceived(): Promise<boolean>;\n isNotificationPermissionGranted(): Promise<boolean>;\n requestNotificationPermission(): Promise<boolean>;\n fetchCurrentLocation(): Promise<null | {\n lat: number;\n lng: number;\n accuracy: number;\n }>;\n fetchIOSLocationPermissionStatus(): Promise<\n | 'notDetermined'\n | 'restricted'\n | 'denied'\n | 'authorizedAlways'\n | 'authorizedWhenInUse'\n | 'authorized'\n | 'unknown'\n >;\n};\n\nexport const OkHiNativeModule: OkHiNativeModuleType = NativeModules.Okhi\n ? NativeModules.Okhi\n : new Proxy(\n {},\n {\n get() {\n throw new Error(LINKING_ERROR);\n },\n }\n );\n\nexport const OkHiNativeEvents = new NativeEventEmitter(NativeModules.Okhi);\n\nOkHiNativeEvents.addListener('onLocationPermissionStatusUpdate', () => null);\n"],"mappings":";;;;;;;AAAA;;AAGA,MAAMA,aAAa,GAChB,4EAAD,GACAC,qBAAA,CAASC,MAAT,CAAgB;EAAEC,GAAG,EAAE,gCAAP;EAAyCC,OAAO,EAAE;AAAlD,CAAhB,CADA,GAEA,sDAFA,GAGA,6CAJF;AAiEO,MAAMC,gBAAsC,GAAGC,0BAAA,CAAcC,IAAd,GAClDD,0BAAA,CAAcC,IADoC,GAElD,IAAIC,KAAJ,CACE,EADF,EAEE;EACEC,GAAG,GAAG;IACJ,MAAM,IAAIC,KAAJ,CAAUV,aAAV,CAAN;EACD;;AAHH,CAFF,CAFG;;AAWA,MAAMW,gBAAgB,GAAG,IAAIC,+BAAJ,CAAuBN,0BAAA,CAAcC,IAArC,CAAzB;;AAEPI,gBAAgB,CAACE,WAAjB,CAA6B,kCAA7B,EAAiE,MAAM,IAAvE"}
1
+ {"version":3,"names":["LINKING_ERROR","Platform","select","ios","default","OkHiNativeModule","NativeModules","Okhi","Proxy","get","Error","OkHiNativeEvents","NativeEventEmitter","addListener"],"sources":["index.ts"],"sourcesContent":["import { NativeModules, NativeEventEmitter, Platform } from 'react-native';\nimport type { OkVerifyStartConfiguration } from '../OkVerify/types';\n\nconst LINKING_ERROR =\n `The package 'react-native-okhi' doesn't seem to be linked. Make sure: \\n\\n` +\n Platform.select({ ios: \"- You have run 'pod install'\\n\", default: '' }) +\n '- You rebuilt the app after installing the package\\n' +\n '- You are not using Expo managed workflow\\n';\n\ntype OkHiNativeModuleType = {\n isLocationServicesEnabled(): Promise<boolean>;\n isLocationPermissionGranted(): Promise<boolean>;\n isBackgroundLocationPermissionGranted(): Promise<boolean>;\n requestLocationPermission(): Promise<boolean>;\n requestBackgroundLocationPermission(): Promise<boolean>;\n requestEnableLocationServices(): Promise<boolean>;\n isGooglePlayServicesAvailable(): Promise<boolean>;\n requestEnableGooglePlayServices(): Promise<boolean>;\n getSystemVersion(): Promise<number | string>;\n getAuthToken(branchId: string, clientKey: string): Promise<string>;\n initialize(configuration: string): Promise<void>;\n startAddressVerification(\n phoneNumber: string,\n locationId: string,\n lat: Number,\n lon: Number,\n configuration?: OkVerifyStartConfiguration,\n fcmPushNotificationToken?: string\n ): Promise<string>;\n stopAddressVerification(\n phoneNumber: string,\n locationId: string\n ): Promise<string>;\n startForegroundService(): Promise<boolean>;\n stopForegroundService(): Promise<boolean>;\n isForegroundServiceRunning(): Promise<boolean>;\n initializeIOS(\n branchId: string,\n clientKey: string,\n environment: string\n ): Promise<boolean>;\n openAppSettings(): Promise<void>;\n retriveLocationPermissionStatus(): Promise<string>;\n requestTrackingAuthorization(): Promise<string | null>;\n canOpenProtectedAppsSettings(): Promise<boolean>;\n openProtectedAppsSettings(): Promise<boolean>;\n retrieveDeviceInfo(): Promise<{\n manufacturer: string;\n model: string;\n osVersion: string;\n platform: 'android' | 'ios';\n }>;\n setItem(key: string, value: string): Promise<boolean>;\n onNewToken(fcmPushNotificationToken: string): Promise<boolean>;\n onMessageReceived(): Promise<boolean>;\n isNotificationPermissionGranted(): Promise<boolean>;\n requestNotificationPermission(): Promise<boolean>;\n fetchCurrentLocation(): Promise<null | {\n lat: number;\n lng: number;\n accuracy: number;\n }>;\n fetchIOSLocationPermissionStatus(): Promise<\n | 'notDetermined'\n | 'restricted'\n | 'denied'\n | 'authorizedAlways'\n | 'authorizedWhenInUse'\n | 'authorized'\n | 'unknown'\n >;\n};\n\nexport const OkHiNativeModule: OkHiNativeModuleType = NativeModules.Okhi\n ? NativeModules.Okhi\n : new Proxy(\n {},\n {\n get() {\n throw new Error(LINKING_ERROR);\n },\n }\n );\n\nexport const OkHiNativeEvents = new NativeEventEmitter(NativeModules.Okhi);\n\nOkHiNativeEvents.addListener('onLocationPermissionStatusUpdate', () => null);\n"],"mappings":";;;;;;;AAAA;;AAGA,MAAMA,aAAa,GAChB,4EAAD,GACAC,qBAAA,CAASC,MAAT,CAAgB;EAAEC,GAAG,EAAE,gCAAP;EAAyCC,OAAO,EAAE;AAAlD,CAAhB,CADA,GAEA,sDAFA,GAGA,6CAJF;AAsEO,MAAMC,gBAAsC,GAAGC,0BAAA,CAAcC,IAAd,GAClDD,0BAAA,CAAcC,IADoC,GAElD,IAAIC,KAAJ,CACE,EADF,EAEE;EACEC,GAAG,GAAG;IACJ,MAAM,IAAIC,KAAJ,CAAUV,aAAV,CAAN;EACD;;AAHH,CAFF,CAFG;;AAWA,MAAMW,gBAAgB,GAAG,IAAIC,+BAAJ,CAAuBN,0BAAA,CAAcC,IAArC,CAAzB;;AAEPI,gBAAgB,CAACE,WAAjB,CAA6B,kCAA7B,EAAiE,MAAM,IAAvE"}
@@ -6,7 +6,7 @@ import { getFrameUrl, generateJavaScriptStartScript, generateStartDataPayload, p
6
6
  import { OkHiException } from '../OkCore/OkHiException';
7
7
  import { OkHiAuth } from '../OkCore/OkHiAuth';
8
8
  import { start as sv } from '../OkVerify';
9
- import { getApplicationConfiguration, openProtectedAppsSettings } from '../OkCore';
9
+ import { getApplicationConfiguration, isBackgroundLocationPermissionGranted, isLocationServicesEnabled, openAppSettings, openProtectedAppsSettings, request, requestLocationPermission } from '../OkCore';
10
10
  import { OkHiNativeModule } from '../OkHiNativeModule';
11
11
  /**
12
12
  * The OkHiLocationManager React Component is used to display an in app modal, enabling the user to quickly create an accurate OkHi address.
@@ -69,12 +69,75 @@ export const OkHiLocationManager = props => {
69
69
  }
70
70
  }, [applicationConfiguration, props, token]);
71
71
 
72
- const handleOnMessage = _ref => {
72
+ const runWebViewCallback = value => {
73
+ if (webViewRef.current) {
74
+ const jsString = `(function (){ if (typeof runOkHiLocationManagerCallback === "function") { runOkHiLocationManagerCallback("${value}") } })()`;
75
+ webViewRef.current.injectJavaScript(jsString);
76
+ }
77
+ };
78
+
79
+ const handleAndroidRequestLocationPermission = async level => {
80
+ // using request for android because we can programmatically turn on location services, unlike yucky ios
81
+ request(level, null, (status, error) => {
82
+ if (error) {
83
+ onError(error);
84
+ } else if (level === 'whenInUse' && status === 'authorizedWhenInUse') {
85
+ runWebViewCallback(level);
86
+ } else if (level === 'always' && status === 'authorizedAlways') {
87
+ runWebViewCallback(level);
88
+ }
89
+ });
90
+ };
91
+
92
+ const handleIOSRequestLocationPermission = async level => {
93
+ const serviceError = new OkHiException({
94
+ code: OkHiException.SERVICE_UNAVAILABLE_CODE,
95
+ message: 'Location service is currently not available. Please enable in app settings'
96
+ });
97
+ const unknownError = new OkHiException({
98
+ code: OkHiException.UNKNOWN_ERROR_CODE,
99
+ message: 'Something went wrong while requesting permissions. Please try again later.'
100
+ });
101
+
102
+ try {
103
+ const isServiceAvailable = await isLocationServicesEnabled();
104
+
105
+ if (!isServiceAvailable) {
106
+ onError(serviceError);
107
+ } else if (level === 'whenInUse' && (await requestLocationPermission())) {
108
+ runWebViewCallback(level);
109
+ } else if (level === 'always') {
110
+ const granted = await isBackgroundLocationPermissionGranted();
111
+
112
+ if (granted) {
113
+ runWebViewCallback(level);
114
+ } else {
115
+ openAppSettings();
116
+ }
117
+ }
118
+ } catch (error) {
119
+ onError(unknownError);
120
+ }
121
+ };
122
+
123
+ const handleRequestLocationPermission = async _ref => {
124
+ let {
125
+ level
126
+ } = _ref;
127
+
128
+ if (Platform.OS === 'android') {
129
+ handleAndroidRequestLocationPermission(level);
130
+ } else if (Platform.OS === 'ios') {
131
+ handleIOSRequestLocationPermission(level);
132
+ }
133
+ };
134
+
135
+ const handleOnMessage = _ref2 => {
73
136
  let {
74
137
  nativeEvent: {
75
138
  data
76
139
  }
77
- } = _ref;
140
+ } = _ref2;
78
141
 
79
142
  try {
80
143
  const response = JSON.parse(data);
@@ -82,13 +145,13 @@ export const OkHiLocationManager = props => {
82
145
  if (response.message === 'fatal_exit') {
83
146
  onError(new OkHiException({
84
147
  code: OkHiException.UNKNOWN_ERROR_CODE,
85
- message: response.payload.toString()
148
+ message: 'Something went wrong, please try again later.'
86
149
  }));
87
150
  } else if (response.message === 'exit_app') {
88
151
  onCloseRequest();
89
152
  } else if (response.message === 'request_enable_protected_apps') {
90
153
  openProtectedAppsSettings();
91
- } else {
154
+ } else if (response.message === 'location_created' || response.message === 'location_selected' || response.message === 'location_updated') {
92
155
  onSuccess({
93
156
  user: { ...response.payload.user,
94
157
  fcmPushNotificationToken: user.fcmPushNotificationToken
@@ -111,6 +174,8 @@ export const OkHiLocationManager = props => {
111
174
  });
112
175
  }
113
176
  });
177
+ } else if (response.message === 'request_location_permission') {
178
+ handleRequestLocationPermission(response.payload);
114
179
  }
115
180
  } catch (error) {
116
181
  let errorMessage = 'Something went wrong';