react-native-okhi 1.1.2 → 1.1.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.
package/ios/Okhi.m CHANGED
@@ -42,4 +42,9 @@ RCT_EXTERN_METHOD(requestTrackingAuthorization: (RCTPromiseResolveBlock)resolve
42
42
  RCT_EXTERN_METHOD(isNotificationPermissionGranted: (RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
43
43
 
44
44
  RCT_EXTERN_METHOD(requestNotificationPermission: (RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
45
+
46
+ RCT_EXTERN_METHOD(fetchCurrentLocation: (RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
47
+
48
+ RCT_EXTERN_METHOD(fetchIOSLocationPermissionStatus: (RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
49
+
45
50
  @end
package/ios/Okhi.swift CHANGED
@@ -16,10 +16,11 @@ class Okhi: RCTEventEmitter {
16
16
  private var didChangeLocationPermissionStatusResolve: RCTPromiseResolveBlock?
17
17
  private var didChangeLocationPermissionStatusReject: RCTPromiseRejectBlock?
18
18
  private var okVerify: OkVerify
19
-
19
+ private var okhiLocationManager: OkHiLocationManager
20
20
 
21
21
  override init() {
22
22
  okVerify = OkVerify()
23
+ okhiLocationManager = OkHiLocationManager()
23
24
  super.init()
24
25
  okVerify.delegate = self
25
26
  }
@@ -129,6 +130,21 @@ class Okhi: RCTEventEmitter {
129
130
  }
130
131
  }
131
132
 
133
+ @objc func fetchCurrentLocation(_ resolve:@escaping RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) {
134
+ okhiLocationManager.getCurrentLocation { result in
135
+ if let location = result {
136
+ let locationDict: NSDictionary = [
137
+ "lat": location.coordinate.latitude,
138
+ "lng": location.coordinate.longitude,
139
+ "accuracy": location.horizontalAccuracy
140
+ ]
141
+ resolve(locationDict)
142
+ } else {
143
+ resolve(NSNull())
144
+ }
145
+ }
146
+ }
147
+
132
148
  override func supportedEvents() -> [String]! {
133
149
  return ["onLocationPermissionStatusUpdate"]
134
150
  }
@@ -153,6 +169,11 @@ class Okhi: RCTEventEmitter {
153
169
  }
154
170
  return str
155
171
  }
172
+
173
+ @objc public func fetchIOSLocationPermissionStatus(_ resolve:@escaping RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) {
174
+ let manager = CLLocationManager()
175
+ resolve(fetchLocationPermissionStatus(status: getLocationAuthorizationStatus(manager: manager)))
176
+ }
156
177
  }
157
178
 
158
179
  // MARK: - OkHi Utils
@@ -185,14 +206,14 @@ extension Okhi: OkVerifyDelegate {
185
206
  self.didChangeLocationPermissionStatusReject = nil
186
207
  }
187
208
  }
188
-
209
+
189
210
  func verify(_ okverify: OkVerify, didInitialize result: Bool) {
190
211
  guard let resolve = initResolve else { return }
191
212
  resolve(result)
192
213
  self.initResolve = nil
193
214
  self.initReject = nil
194
215
  }
195
-
216
+
196
217
  func verify(_ okverify: OkVerify, didEncounterError error: OkVerifyError) {
197
218
  if let initReject = initReject {
198
219
  initReject(error.code, error.message, error)
@@ -204,13 +225,13 @@ extension Okhi: OkVerifyDelegate {
204
225
  self.reject = nil
205
226
  }
206
227
  }
207
-
228
+
208
229
  func verify(_ okverify: OkVerify, didStartAddressVerificationFor locationId: String) {
209
230
  guard let resolve = resolve else { return }
210
231
  resolve(locationId)
211
232
  self.resolve = nil
212
233
  }
213
-
234
+
214
235
  func verify(_ okverify: OkVerify, didStopVerificationFor locationId: String) {
215
236
  guard let resolve = resolve else { return }
216
237
  resolve(locationId)
@@ -15,9 +15,15 @@ var _OkHiNativeModule = require("../OkHiNativeModule");
15
15
 
16
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
17
 
18
+ const fetchCurrentLocation = async () => {
19
+ const result = await _OkHiNativeModule.OkHiNativeModule.fetchCurrentLocation();
20
+ return result;
21
+ };
18
22
  /**
19
23
  * @ignore
20
24
  */
25
+
26
+
21
27
  const generateStartDataPayload = async (props, authToken, applicationConfiguration) => {
22
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;
23
29
 
@@ -54,29 +60,64 @@ const generateStartDataPayload = async (props, authToken, applicationConfigurati
54
60
  name: 'react-native'
55
61
  }
56
62
  };
57
- let hasLocationPermission;
63
+ payload.config = {
64
+ streetView: typeof ((_props$config = props.config) === null || _props$config === void 0 ? void 0 : _props$config.streetView) === 'boolean' ? props.config.streetView : true,
65
+ appBar: {
66
+ color: (_props$theme3 = props.theme) === null || _props$theme3 === void 0 ? void 0 : (_props$theme3$appBar = _props$theme3.appBar) === null || _props$theme3$appBar === void 0 ? void 0 : _props$theme3$appBar.backgroundColor,
67
+ visible: (_props$config2 = props.config) === null || _props$config2 === void 0 ? void 0 : (_props$config2$appBar = _props$config2.appBar) === null || _props$config2$appBar === void 0 ? void 0 : _props$config2$appBar.visible
68
+ },
69
+ addressTypes: {
70
+ 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
+ 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
+ },
73
+ protectedApps: _reactNative.Platform.OS === 'android' && (await (0, _OkCore.canOpenProtectedAppsSettings)())
74
+ };
58
75
 
59
- try {
60
- hasLocationPermission = await (0, _OkCore.isLocationPermissionGranted)();
61
- } catch (error) {
62
- console.log(error);
63
- }
76
+ if (_reactNative.Platform.OS === 'ios') {
77
+ const status = await _OkHiNativeModule.OkHiNativeModule.fetchIOSLocationPermissionStatus();
78
+
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
+ }
96
+ }
97
+ }
98
+ } else if (_reactNative.Platform.OS === 'android') {
99
+ let hasLocationPermission;
100
+
101
+ try {
102
+ hasLocationPermission = await (0, _OkCore.isLocationPermissionGranted)();
103
+ } catch (error) {
104
+ console.log(error);
105
+ }
64
106
 
65
- let hasBackgroundLocationPermission;
107
+ let hasBackgroundLocationPermission;
66
108
 
67
- try {
68
- hasBackgroundLocationPermission = await (0, _OkCore.isBackgroundLocationPermissionGranted)();
69
- } catch (error) {
70
- console.log(error);
71
- }
109
+ try {
110
+ hasBackgroundLocationPermission = await (0, _OkCore.isBackgroundLocationPermissionGranted)();
111
+ } catch (error) {
112
+ console.log(error);
113
+ }
72
114
 
73
- if (typeof hasLocationPermission === 'boolean' && typeof hasBackgroundLocationPermission === 'boolean') {
74
- payload.context.permissions = {
75
- location: hasBackgroundLocationPermission ? 'always' : hasLocationPermission ? 'whenInUse' : 'denied'
76
- };
77
- }
115
+ if (typeof hasLocationPermission === 'boolean' && typeof hasBackgroundLocationPermission === 'boolean') {
116
+ payload.context.permissions = {
117
+ location: hasBackgroundLocationPermission ? 'always' : hasLocationPermission ? 'whenInUse' : 'denied'
118
+ };
119
+ }
78
120
 
79
- if (_reactNative.Platform.OS === 'android') {
80
121
  const {
81
122
  manufacturer,
82
123
  model
@@ -85,22 +126,13 @@ const generateStartDataPayload = async (props, authToken, applicationConfigurati
85
126
  manufacturer,
86
127
  model
87
128
  };
88
- payload.context.permissions = { ...payload.context.permissions
89
- };
129
+ } else {
130
+ throw new _OkCore.OkHiException({
131
+ code: _OkCore.OkHiException.UNSUPPORTED_PLATFORM_CODE,
132
+ message: _OkCore.OkHiException.UNAUTHORIZED_MESSAGE
133
+ });
90
134
  }
91
135
 
92
- payload.config = {
93
- protectedApps: _reactNative.Platform.OS === 'android' && (await (0, _OkCore.canOpenProtectedAppsSettings)()),
94
- streetView: typeof ((_props$config = props.config) === null || _props$config === void 0 ? void 0 : _props$config.streetView) === 'boolean' ? props.config.streetView : true,
95
- appBar: {
96
- color: (_props$theme3 = props.theme) === null || _props$theme3 === void 0 ? void 0 : (_props$theme3$appBar = _props$theme3.appBar) === null || _props$theme3$appBar === void 0 ? void 0 : _props$theme3$appBar.backgroundColor,
97
- visible: (_props$config2 = props.config) === null || _props$config2 === void 0 ? void 0 : (_props$config2$appBar = _props$config2.appBar) === null || _props$config2$appBar === void 0 ? void 0 : _props$config2$appBar.visible
98
- },
99
- addressTypes: {
100
- 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,
101
- 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
102
- }
103
- };
104
136
  return payload;
105
137
  };
106
138
  /**
@@ -1 +1 @@
1
- {"version":3,"names":["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","hasLocationPermission","isLocationPermissionGranted","error","console","log","hasBackgroundLocationPermission","isBackgroundLocationPermissionGranted","permissions","location","Platform","OS","manufacturer","model","OkHiNativeModule","retrieveDeviceInfo","device","config","protectedApps","canOpenProtectedAppsSettings","streetView","backgroundColor","visible","addressTypes","home","work","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","lat","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 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\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\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\n if (Platform.OS === 'android') {\n const { manufacturer, model } = await OkHiNativeModule.retrieveDeviceInfo();\n payload.context.device = {\n manufacturer,\n model,\n };\n payload.context.permissions = {\n ...payload.context.permissions,\n };\n }\n payload.config = {\n protectedApps:\n Platform.OS === 'android' && (await canOpenProtectedAppsSettings()),\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 };\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;;AAWA;;AAEA;;AACA;;;;AAEA;AACA;AACA;AACO,MAAMA,wBAAwB,GAAG,OACtCC,KADsC,EAEtCC,SAFsC,EAGtCC,wBAHsC,KAIW;EAAA;;EACjD,MAAMC,OAAY,GAAG,EAArB;EACAA,OAAO,CAACC,KAAR,GAAgB,CAACJ,KAAK,CAACK,KAAP,GACZC,SADY,GAEZ;IACEC,IAAI,EAAE;MACJC,KAAK,kBAAER,KAAK,CAACK,KAAR,wEAAE,aAAaI,MAAf,wDAAE,oBAAqBC,OADxB;MAEJC,IAAI,mBAAEX,KAAK,CAACK,KAAR,0EAAE,cAAaO,MAAf,yDAAE,qBAAqBD,IAFvB;MAGJE,IAAI,2BAAEX,wBAAwB,CAACY,GAA3B,0DAAE,sBAA8BD;IAHhC;EADR,CAFJ;EASAV,OAAO,CAACY,IAAR,GAAe;IACbC,KAAK,EAAEhB,KAAK,CAACe,IAAN,CAAWC,KADL;IAEbC,SAAS,EAAEjB,KAAK,CAACe,IAAN,CAAWE,SAFT;IAGbC,QAAQ,EAAElB,KAAK,CAACe,IAAN,CAAWG,QAHR;IAIbC,KAAK,EAAEnB,KAAK,CAACe,IAAN,CAAWI;EAJL,CAAf;EAMAhB,OAAO,CAACiB,IAAR,GAAe;IACbnB;EADa,CAAf;EAGAE,OAAO,CAACkB,OAAR,GAAkB;IAChBC,SAAS,EAAE;MACTT,IAAI,4BAAEX,wBAAwB,CAACY,GAA3B,2DAAE,uBAA8BD,IAD3B;MAETU,OAAO,4BAA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QAAF,uBAAEA,QAAQ,CAAEiE,IArBX;IAsBLC,WAAW,EAAElE,QAAF,aAAEA,QAAF,uBAAEA,QAAQ,CAAEmE;EAtBlB,CAAP;AAwBD,CAzBM"}
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,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;EACAA,OAAO,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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,4 +1,4 @@
1
1
  {
2
2
  "name": "okhiWebReactNative",
3
- "version": "1.1.2"
3
+ "version": "1.1.3-beta.1"
4
4
  }
@@ -15,6 +15,8 @@ var _ = require("./");
15
15
 
16
16
  var _OkHiNativeModule = require("../OkHiNativeModule");
17
17
 
18
+ var _reactNative = require("react-native");
19
+
18
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
21
 
20
22
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
@@ -85,7 +87,10 @@ class OkHiAuth {
85
87
  } = await _axios.default.post(url, payload, {
86
88
  headers
87
89
  });
88
- await _OkHiNativeModule.OkHiNativeModule.setItem('okhi:recent:token', data.authorization_token); //TODO: move all anonymousSignIn to native code
90
+
91
+ if (_reactNative.Platform.OS === 'android') {
92
+ await _OkHiNativeModule.OkHiNativeModule.setItem('okhi:recent:token', data.authorization_token); //TODO: move all anonymousSignIn to native code
93
+ }
89
94
 
90
95
  resolve(data.authorization_token);
91
96
  }
@@ -1 +1 @@
1
- {"version":3,"names":["OkHiAuth","API_VERSION","ANONYMOUS_SIGN_IN_ENDPOINT","anonymousSignInWithPhoneNumber","phone","scopes","config","anonymousSignIn","anonymousSignInWithUserId","userId","user_id","payload","Promise","resolve","reject","getApplicationConfiguration","auth","token","OkHiException","code","UNAUTHORIZED_CODE","message","UNAUTHORIZED_MESSAGE","context","url","SANDBOX_BASE_URL","mode","DEV_BASE_URL","OkHiMode","PROD","PROD_BASE_URL","headers","Authorization","data","axios","post","OkHiNativeModule","setItem","authorization_token","error","parseRequestError","response","NETWORK_ERROR_CODE","NETWORK_ERROR_MESSAGE","status","INVALID_PHONE_CODE","INVALID_PHONE_MESSAGE","UNKNOWN_ERROR_CODE","UNKNOWN_ERROR_MESSAGE"],"sources":["OkHiAuth.ts"],"sourcesContent":["import axios from 'axios';\nimport { OkHiMode } from './OkHiMode';\nimport { OkHiException } from './OkHiException';\nimport type { AuthApplicationConfig, OkHiAccessScope } from './_types';\nimport { getApplicationConfiguration } from './';\nimport { OkHiNativeModule } from '../OkHiNativeModule';\n\n/**\n * @ignore\n */\nexport class OkHiAuth {\n private readonly API_VERSION = 'v5';\n private readonly ANONYMOUS_SIGN_IN_ENDPOINT = '/auth/anonymous-signin';\n private readonly DEV_BASE_URL =\n `https://dev-api.okhi.io/${this.API_VERSION}` +\n this.ANONYMOUS_SIGN_IN_ENDPOINT;\n private readonly SANDBOX_BASE_URL =\n `https://sandbox-api.okhi.io/${this.API_VERSION}` +\n this.ANONYMOUS_SIGN_IN_ENDPOINT;\n private readonly PROD_BASE_URL =\n `https://api.okhi.io/${this.API_VERSION}` + this.ANONYMOUS_SIGN_IN_ENDPOINT;\n private config: AuthApplicationConfig | null = null;\n\n anonymousSignInWithPhoneNumber(\n phone: string,\n scopes: Array<OkHiAccessScope>,\n config: AuthApplicationConfig\n ) {\n this.config = config;\n return this.anonymousSignIn({\n scopes,\n phone,\n });\n }\n\n protected anonymousSignInWithUserId(\n userId: string,\n scopes: Array<OkHiAccessScope>\n ) {\n return this.anonymousSignIn({\n scopes,\n user_id: userId,\n });\n }\n\n private async anonymousSignIn(payload: {\n scopes: Array<OkHiAccessScope>;\n [key: string]: any;\n }): Promise<string> {\n return new Promise(async (resolve, reject) => {\n try {\n const config = this.config || (await getApplicationConfiguration());\n if (config === null || !config.auth || !config.auth.token) {\n reject(\n new OkHiException({\n code: OkHiException.UNAUTHORIZED_CODE,\n message: OkHiException.UNAUTHORIZED_MESSAGE,\n })\n );\n } else {\n const { auth, context } = config;\n let url = this.SANDBOX_BASE_URL;\n if (context?.mode === ('dev' as any)) {\n url = this.DEV_BASE_URL;\n } else if (context?.mode === OkHiMode.PROD) {\n url = this.PROD_BASE_URL;\n } else {\n url = this.SANDBOX_BASE_URL;\n }\n const headers = { Authorization: auth.token };\n const { data } = await axios.post(url, payload, {\n headers,\n });\n await OkHiNativeModule.setItem(\n 'okhi:recent:token',\n data.authorization_token\n ); //TODO: move all anonymousSignIn to native code\n resolve(data.authorization_token);\n }\n } catch (error) {\n reject(this.parseRequestError(error));\n }\n });\n }\n\n private parseRequestError(error: any) {\n if (!error.response) {\n return new OkHiException({\n code: OkHiException.NETWORK_ERROR_CODE,\n message: OkHiException.NETWORK_ERROR_MESSAGE,\n });\n }\n switch (error.response.status) {\n case 400:\n return new OkHiException({\n code: OkHiException.INVALID_PHONE_CODE,\n message: OkHiException.INVALID_PHONE_MESSAGE,\n });\n case 401:\n return new OkHiException({\n code: OkHiException.UNAUTHORIZED_CODE,\n message: OkHiException.UNAUTHORIZED_MESSAGE,\n });\n default:\n return new OkHiException({\n code: OkHiException.UNKNOWN_ERROR_CODE,\n message: error.message || OkHiException.UNKNOWN_ERROR_MESSAGE,\n });\n }\n }\n}\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAEA;;AACA;;;;;;AAEA;AACA;AACA;AACO,MAAMA,QAAN,CAAe;EAAA;IAAA,qCACW,IADX;;IAAA,oDAE0B,wBAF1B;;IAAA,sCAIjB,2BAA0B,KAAKC,WAAY,EAA5C,GACA,KAAKC,0BALa;;IAAA,0CAOjB,+BAA8B,KAAKD,WAAY,EAAhD,GACA,KAAKC,0BAR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EvB1B,OAAO,EAAEkB,KAAK,CAAClB,OAAN,IAAiBH,4BAAA,CAAc8B;QAFjB,CAAlB,CAAP;IAZJ;EAiBD;;AAnGmB"}
1
+ {"version":3,"names":["OkHiAuth","API_VERSION","ANONYMOUS_SIGN_IN_ENDPOINT","anonymousSignInWithPhoneNumber","phone","scopes","config","anonymousSignIn","anonymousSignInWithUserId","userId","user_id","payload","Promise","resolve","reject","getApplicationConfiguration","auth","token","OkHiException","code","UNAUTHORIZED_CODE","message","UNAUTHORIZED_MESSAGE","context","url","SANDBOX_BASE_URL","mode","DEV_BASE_URL","OkHiMode","PROD","PROD_BASE_URL","headers","Authorization","data","axios","post","Platform","OS","OkHiNativeModule","setItem","authorization_token","error","parseRequestError","response","NETWORK_ERROR_CODE","NETWORK_ERROR_MESSAGE","status","INVALID_PHONE_CODE","INVALID_PHONE_MESSAGE","UNKNOWN_ERROR_CODE","UNKNOWN_ERROR_MESSAGE"],"sources":["OkHiAuth.ts"],"sourcesContent":["import axios from 'axios';\nimport { OkHiMode } from './OkHiMode';\nimport { OkHiException } from './OkHiException';\nimport type { AuthApplicationConfig, OkHiAccessScope } from './_types';\nimport { getApplicationConfiguration } from './';\nimport { OkHiNativeModule } from '../OkHiNativeModule';\nimport { Platform } from 'react-native';\n\n/**\n * @ignore\n */\nexport class OkHiAuth {\n private readonly API_VERSION = 'v5';\n private readonly ANONYMOUS_SIGN_IN_ENDPOINT = '/auth/anonymous-signin';\n private readonly DEV_BASE_URL =\n `https://dev-api.okhi.io/${this.API_VERSION}` +\n this.ANONYMOUS_SIGN_IN_ENDPOINT;\n private readonly SANDBOX_BASE_URL =\n `https://sandbox-api.okhi.io/${this.API_VERSION}` +\n this.ANONYMOUS_SIGN_IN_ENDPOINT;\n private readonly PROD_BASE_URL =\n `https://api.okhi.io/${this.API_VERSION}` + this.ANONYMOUS_SIGN_IN_ENDPOINT;\n private config: AuthApplicationConfig | null = null;\n\n anonymousSignInWithPhoneNumber(\n phone: string,\n scopes: Array<OkHiAccessScope>,\n config: AuthApplicationConfig\n ) {\n this.config = config;\n return this.anonymousSignIn({\n scopes,\n phone,\n });\n }\n\n protected anonymousSignInWithUserId(\n userId: string,\n scopes: Array<OkHiAccessScope>\n ) {\n return this.anonymousSignIn({\n scopes,\n user_id: userId,\n });\n }\n\n private async anonymousSignIn(payload: {\n scopes: Array<OkHiAccessScope>;\n [key: string]: any;\n }): Promise<string> {\n return new Promise(async (resolve, reject) => {\n try {\n const config = this.config || (await getApplicationConfiguration());\n if (config === null || !config.auth || !config.auth.token) {\n reject(\n new OkHiException({\n code: OkHiException.UNAUTHORIZED_CODE,\n message: OkHiException.UNAUTHORIZED_MESSAGE,\n })\n );\n } else {\n const { auth, context } = config;\n let url = this.SANDBOX_BASE_URL;\n if (context?.mode === ('dev' as any)) {\n url = this.DEV_BASE_URL;\n } else if (context?.mode === OkHiMode.PROD) {\n url = this.PROD_BASE_URL;\n } else {\n url = this.SANDBOX_BASE_URL;\n }\n const headers = { Authorization: auth.token };\n const { data } = await axios.post(url, payload, {\n headers,\n });\n if (Platform.OS === 'android') {\n await OkHiNativeModule.setItem(\n 'okhi:recent:token',\n data.authorization_token\n ); //TODO: move all anonymousSignIn to native code\n }\n resolve(data.authorization_token);\n }\n } catch (error) {\n reject(this.parseRequestError(error));\n }\n });\n }\n\n private parseRequestError(error: any) {\n if (!error.response) {\n return new OkHiException({\n code: OkHiException.NETWORK_ERROR_CODE,\n message: OkHiException.NETWORK_ERROR_MESSAGE,\n });\n }\n switch (error.response.status) {\n case 400:\n return new OkHiException({\n code: OkHiException.INVALID_PHONE_CODE,\n message: OkHiException.INVALID_PHONE_MESSAGE,\n });\n case 401:\n return new OkHiException({\n code: OkHiException.UNAUTHORIZED_CODE,\n message: OkHiException.UNAUTHORIZED_MESSAGE,\n });\n default:\n return new OkHiException({\n code: OkHiException.UNKNOWN_ERROR_CODE,\n message: error.message || OkHiException.UNKNOWN_ERROR_MESSAGE,\n });\n }\n }\n}\n"],"mappings":";;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EAAED,4BAAA,CAAc6B,kBADG;UAEvB1B,OAAO,EAAEH,4BAAA,CAAc8B;QAFA,CAAlB,CAAP;;MAIF,KAAK,GAAL;QACE,OAAO,IAAI9B,4BAAJ,CAAkB;UACvBC,IAAI,EAAED,4BAAA,CAAcE,iBADG;UAEvBC,OAAO,EAAEH,4BAAA,CAAcI;QAFA,CAAlB,CAAP;;MAIF;QACE,OAAO,IAAIJ,4BAAJ,CAAkB;UACvBC,IAAI,EAAED,4BAAA,CAAc+B,kBADG;UAEvB5B,OAAO,EAAEoB,KAAK,CAACpB,OAAN,IAAiBH,4BAAA,CAAcgC;QAFjB,CAAlB,CAAP;IAZJ;EAiBD;;AArGmB"}
@@ -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};\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;AAmDO,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<{ 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"}
@@ -253,7 +253,11 @@ const checkVerificationStartRequirements = () => {
253
253
  exports.checkVerificationStartRequirements = checkVerificationStartRequirements;
254
254
 
255
255
  const onNewToken = fcmPushNotificationToken => {
256
- return (0, _helpers.isValidPlatform)(() => (0, _helpers.errorHandler)(() => _OkHiNativeModule.OkHiNativeModule.onNewToken(fcmPushNotificationToken)), 'android');
256
+ if (_reactNative.Platform.OS === 'android') {
257
+ return _OkHiNativeModule.OkHiNativeModule.onNewToken(fcmPushNotificationToken);
258
+ }
259
+
260
+ return Promise.resolve(true);
257
261
  };
258
262
  /**
259
263
  * Android Only - Should be invoked only when push notification is received.
@@ -264,7 +268,11 @@ const onNewToken = fcmPushNotificationToken => {
264
268
  exports.onNewToken = onNewToken;
265
269
 
266
270
  const onMessageReceived = () => {
267
- return (0, _helpers.isValidPlatform)(() => (0, _helpers.errorHandler)(_OkHiNativeModule.OkHiNativeModule.onMessageReceived), 'android');
271
+ if (_reactNative.Platform.OS === 'android') {
272
+ return _OkHiNativeModule.OkHiNativeModule.onMessageReceived();
273
+ }
274
+
275
+ return Promise.resolve(true);
268
276
  };
269
277
 
270
278
  exports.onMessageReceived = onMessageReceived;
@@ -1 +1 @@
1
- {"version":3,"names":["start","phoneNumber","locationId","lat","lon","configuration","fcmPushNotificationToken","isValidPlatform","Platform","OS","OkHiNativeModule","startAddressVerification","startVerification","response","Promise","resolve","reject","location","user","id","result","phone","OkHiException","code","BAD_REQUEST_CODE","message","stopVerification","stopAddressVerification","startForegroundService","errorHandler","stopForegroundService","isForegroundServiceRunning","canStartVerification","requestServices","locationServicesStatus","isLocationServicesEnabled","googlePlayServices","isGooglePlayServicesAvailable","backgroundLocationPerm","isBackgroundLocationPermissionGranted","whenInUseLocationPerm","isLocationPermissionGranted","SERVICE_UNAVAILABLE_CODE","iosPerm","requestBackgroundLocationPermission","locationServicesRequestStatus","requestEnableLocationServices","gPlayServices","requestEnableGooglePlayServices","androidPerm","requestLocationPermission","UNSUPPORTED_PLATFORM_CODE","UNSUPPORTED_PLATFORM_MESSAGE","checkVerificationStartRequirements","isPlayServicesAvailable","PLAY_SERVICES_UNAVAILABLE_CODE","LOCATION_SERVICES_UNAVAILABLE_CODE","PERMISSION_DENIED_CODE","onNewToken","onMessageReceived"],"sources":["index.ts"],"sourcesContent":["import { Platform } from 'react-native';\nimport {\n isBackgroundLocationPermissionGranted,\n isGooglePlayServicesAvailable,\n isLocationServicesEnabled,\n requestBackgroundLocationPermission,\n requestEnableGooglePlayServices,\n requestEnableLocationServices,\n requestLocationPermission,\n isLocationPermissionGranted,\n} from '../OkCore/Helpers';\nimport { errorHandler, isValidPlatform } from '../OkCore/_helpers';\nimport { OkHiNativeModule } from '../OkHiNativeModule';\nimport type { OkVerifyStartConfiguration } from './types';\nimport type { OkCollectSuccessResponse } from '../OkCollect/types';\nimport { OkHiException } from '../OkCore/OkHiException';\nexport * from './types';\n/**\n * Starts verification for a particular address\n * @param {string} phoneNumber A users phone number\n * @param {string} locationId An OkHi location identifier obtained after successfull creation of addresses.\n * @param {number} lat The latitude of the created address\n * @param {number} lon The longitude of the created address\n * @param {Object} configuration Configures how verification will start on different platforms\n * @param {Object} configuration.android Specifices how verification will start on Android platforms\n * @param {boolean} configuration.android.withForeground Specifices if the foreground service will be turned on to speed up rate of verification, default is true\n * @param {string} fcmPushNotificationToken User's firebase push notification token\n * @returns {Promise<string>} A promise that resolves to a string value of the location identifier\n */\nexport const start = (\n phoneNumber: string,\n locationId: string,\n lat: number,\n lon: number,\n configuration?: OkVerifyStartConfiguration,\n fcmPushNotificationToken?: string\n) => {\n return isValidPlatform(() => {\n if (Platform.OS === 'android') {\n return OkHiNativeModule.startAddressVerification(\n phoneNumber,\n locationId,\n lat,\n lon,\n configuration,\n fcmPushNotificationToken\n );\n } else {\n return OkHiNativeModule.startAddressVerification(\n phoneNumber,\n locationId,\n lat,\n lon\n );\n }\n });\n};\n\n/**\n * Starts verification for a particular address using the response object returned by OkCollect\n * @param {Object} response Response returned by OkCollect\n * @param {Object} configuration Configures how verification will start on different platforms\n * @param {Object} configuration.android Specifices how verification will start on Android platforms\n * @param {boolean} configuration.android.withForeground Specifices if the foreground service will be turned on to speed up rate of verification\n * @returns {Promise<string>} A promise that resolves to a string value of the location identifier\n */\nexport const startVerification = async (\n response: OkCollectSuccessResponse,\n configuration?: OkVerifyStartConfiguration\n) => {\n return new Promise((resolve, reject) => {\n const { location, user } = response;\n if (location.id) {\n if (Platform.OS === 'android') {\n const result = OkHiNativeModule.startAddressVerification(\n user.phone,\n location.id,\n location.lat,\n location.lon,\n configuration,\n user.fcmPushNotificationToken\n );\n resolve(result);\n } else {\n const result = OkHiNativeModule.startAddressVerification(\n user.phone,\n location.id,\n location.lat,\n location.lon\n );\n resolve(result);\n }\n } else {\n reject(\n new OkHiException({\n code: OkHiException.BAD_REQUEST_CODE,\n message: 'Missing location id from response',\n })\n );\n }\n });\n};\n\n/**\n * Stops verification for a particular address using a user's phonenumber and OkHi location identifier\n * @param {string} phoneNumber The user's phone number\n * @param {string} locationId An OkHi location identifier obtained after successfull creation of addresses.\n * @returns {Promise<string>} A promise that resolves to a string value of the location identifier\n */\nexport const stopVerification = (phoneNumber: string, locationId: string) => {\n return isValidPlatform(() =>\n OkHiNativeModule.stopAddressVerification(phoneNumber, locationId)\n );\n};\n\n/**\n * Android Only - Starts a foreground service that speeds up rate of verification\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service has started successfully\n */\nexport const startForegroundService = () => {\n return isValidPlatform(\n () => errorHandler(OkHiNativeModule.startForegroundService),\n 'android'\n );\n};\n\n/**\n * Android Only - Stops previously started foreground services\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service has stopped successfully\n */\nexport const stopForegroundService = () => {\n return isValidPlatform(OkHiNativeModule.stopForegroundService, 'android');\n};\n\n/**\n * Android Only - Checks if the foreground service is running\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service is running\n */\nexport const isForegroundServiceRunning = () => {\n return isValidPlatform(\n OkHiNativeModule.isForegroundServiceRunning,\n 'android'\n );\n};\n\n/**\n * Checks whether all necessary permissions and services are available in order to start the address verification process\n * @param {Object} configuration Object that determines whether or not to request these permissions and services from the user\n * @param {boolean} configuration.requestServices Flag that determines whether to request the services from the user\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether or not all conditions are met to start the address verification process\n */\nexport const canStartVerification = (configuration?: {\n requestServices?: boolean;\n}): Promise<boolean> => {\n return new Promise(async (resolve, reject) => {\n const requestServices = configuration && configuration.requestServices;\n const locationServicesStatus = await isLocationServicesEnabled();\n const googlePlayServices =\n Platform.OS === 'android' ? await isGooglePlayServicesAvailable() : true;\n const backgroundLocationPerm =\n await isBackgroundLocationPermissionGranted();\n const whenInUseLocationPerm = await isLocationPermissionGranted();\n if (!requestServices) {\n resolve(\n locationServicesStatus && googlePlayServices && backgroundLocationPerm\n );\n return;\n }\n if (Platform.OS === 'ios') {\n if (!locationServicesStatus) {\n reject(\n new OkHiException({\n code: OkHiException.SERVICE_UNAVAILABLE_CODE,\n message: 'Location services is unavailable',\n })\n );\n return;\n }\n if (backgroundLocationPerm) {\n resolve(true);\n return;\n }\n if (whenInUseLocationPerm && !backgroundLocationPerm) {\n resolve(false);\n return;\n }\n const iosPerm = await requestBackgroundLocationPermission();\n resolve(iosPerm);\n return;\n } else if (Platform.OS === 'android') {\n const locationServicesRequestStatus =\n (await requestEnableLocationServices()) as boolean;\n const gPlayServices = await requestEnableGooglePlayServices();\n const androidPerm =\n (await requestLocationPermission()) &&\n (await requestBackgroundLocationPermission());\n resolve(locationServicesRequestStatus && gPlayServices && androidPerm);\n } else {\n reject(\n new OkHiException({\n code: OkHiException.UNSUPPORTED_PLATFORM_CODE,\n message: OkHiException.UNSUPPORTED_PLATFORM_MESSAGE,\n })\n );\n }\n });\n};\n\n/**\n * Checks whether all necessary permissions and services are available in order to start the address verification process\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether or not all conditions are met to start the address verification process\n */\nexport const checkVerificationStartRequirements = (): Promise<boolean> => {\n return new Promise(async (resolve, reject) => {\n if (Platform.OS === 'android') {\n const isPlayServicesAvailable = await isGooglePlayServicesAvailable();\n if (!isPlayServicesAvailable) {\n reject(\n new OkHiException({\n code: OkHiException.PLAY_SERVICES_UNAVAILABLE_CODE,\n message: 'Google Play Services is unavailable',\n })\n );\n return;\n }\n }\n if (!(await isLocationServicesEnabled())) {\n reject(\n new OkHiException({\n code: OkHiException.LOCATION_SERVICES_UNAVAILABLE_CODE,\n message: 'Location services unavailable',\n })\n );\n return;\n }\n if (!(await isBackgroundLocationPermissionGranted())) {\n reject(\n new OkHiException({\n code: OkHiException.PERMISSION_DENIED_CODE,\n message: 'Background Location permission not granted',\n })\n );\n return;\n }\n resolve(true);\n });\n};\n\n/**\n * Android Only - Updates user's device firebase push notification token\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service has started successfully\n */\nexport const onNewToken = (fcmPushNotificationToken: string) => {\n return isValidPlatform(\n () =>\n errorHandler(() => OkHiNativeModule.onNewToken(fcmPushNotificationToken)),\n 'android'\n );\n};\n\n/**\n * Android Only - Should be invoked only when push notification is received.\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service has started successfully\n */\nexport const onMessageReceived = () => {\n return isValidPlatform(\n () => errorHandler(OkHiNativeModule.onMessageReceived),\n 'android'\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AAUA;;AACA;;AAGA;;AACA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,KAAK,GAAG,CACnBC,WADmB,EAEnBC,UAFmB,EAGnBC,GAHmB,EAInBC,GAJmB,EAKnBC,aALmB,EAMnBC,wBANmB,KAOhB;EACH,OAAO,IAAAC,wBAAA,EAAgB,MAAM;IAC3B,IAAIC,qBAAA,CAASC,EAAT,KAAgB,SAApB,EAA+B;MAC7B,OAAOC,kCAAA,CAAiBC,wBAAjB,CACLV,WADK,EAELC,UAFK,EAGLC,GAHK,EAILC,GAJK,EAKLC,aALK,EAMLC,wBANK,C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AAM,CACJ,IAAIM,4BAAJ,CAAkB;UAChBC,IAAI,EAAED,4BAAA,CAAciC,8BADJ;UAEhB9B,OAAO,EAAE;QAFO,CAAlB,CADI,CAAN;QAMA;MACD;IACF;;IACD,IAAI,EAAE,MAAM,IAAAU,kCAAA,GAAR,CAAJ,EAA0C;MACxCnB,MAAM,CACJ,IAAIM,4BAAJ,CAAkB;QAChBC,IAAI,EAAED,4BAAA,CAAckC,kCADJ;QAEhB/B,OAAO,EAAE;MAFO,CAAlB,CADI,CAAN;MAMA;IACD;;IACD,IAAI,EAAE,MAAM,IAAAc,8CAAA,GAAR,CAAJ,EAAsD;MACpDvB,MAAM,CACJ,IAAIM,4BAAJ,CAAkB;QAChBC,IAAI,EAAED,4BAAA,CAAcmC,sBADJ;QAEhBhC,OAAO,EAAE;MAFO,CAAlB,CADI,CAAN;MAMA;IACD;;IACDV,OAAO,CAAC,IAAD,CAAP;EACD,CAhCM,CAAP;AAiCD,CAlCM;AAoCP;AACA;AACA;AACA;;;;;AACO,MAAM2C,UAAU,GAAIpD,wBAAD,IAAsC;EAC9D,OAAO,IAAAC,wBAAA,EACL,MACE,IAAAsB,qBAAA,EAAa,MAAMnB,kCAAA,CAAiBgD,UAAjB,CAA4BpD,wBAA5B,CAAnB,CAFG,EAGL,SAHK,CAAP;AAKD,CANM;AAQP;AACA;AACA;AACA;;;;;AACO,MAAMqD,iBAAiB,GAAG,MAAM;EACrC,OAAO,IAAApD,wBAAA,EACL,MAAM,IAAAsB,qBAAA,EAAanB,kCAAA,CAAiBiD,iBAA9B,CADD,EAEL,SAFK,CAAP;AAID,CALM"}
1
+ {"version":3,"names":["start","phoneNumber","locationId","lat","lon","configuration","fcmPushNotificationToken","isValidPlatform","Platform","OS","OkHiNativeModule","startAddressVerification","startVerification","response","Promise","resolve","reject","location","user","id","result","phone","OkHiException","code","BAD_REQUEST_CODE","message","stopVerification","stopAddressVerification","startForegroundService","errorHandler","stopForegroundService","isForegroundServiceRunning","canStartVerification","requestServices","locationServicesStatus","isLocationServicesEnabled","googlePlayServices","isGooglePlayServicesAvailable","backgroundLocationPerm","isBackgroundLocationPermissionGranted","whenInUseLocationPerm","isLocationPermissionGranted","SERVICE_UNAVAILABLE_CODE","iosPerm","requestBackgroundLocationPermission","locationServicesRequestStatus","requestEnableLocationServices","gPlayServices","requestEnableGooglePlayServices","androidPerm","requestLocationPermission","UNSUPPORTED_PLATFORM_CODE","UNSUPPORTED_PLATFORM_MESSAGE","checkVerificationStartRequirements","isPlayServicesAvailable","PLAY_SERVICES_UNAVAILABLE_CODE","LOCATION_SERVICES_UNAVAILABLE_CODE","PERMISSION_DENIED_CODE","onNewToken","onMessageReceived"],"sources":["index.ts"],"sourcesContent":["import { Platform } from 'react-native';\nimport {\n isBackgroundLocationPermissionGranted,\n isGooglePlayServicesAvailable,\n isLocationServicesEnabled,\n requestBackgroundLocationPermission,\n requestEnableGooglePlayServices,\n requestEnableLocationServices,\n requestLocationPermission,\n isLocationPermissionGranted,\n} from '../OkCore/Helpers';\nimport { errorHandler, isValidPlatform } from '../OkCore/_helpers';\nimport { OkHiNativeModule } from '../OkHiNativeModule';\nimport type { OkVerifyStartConfiguration } from './types';\nimport type { OkCollectSuccessResponse } from '../OkCollect/types';\nimport { OkHiException } from '../OkCore/OkHiException';\nexport * from './types';\n/**\n * Starts verification for a particular address\n * @param {string} phoneNumber A users phone number\n * @param {string} locationId An OkHi location identifier obtained after successfull creation of addresses.\n * @param {number} lat The latitude of the created address\n * @param {number} lon The longitude of the created address\n * @param {Object} configuration Configures how verification will start on different platforms\n * @param {Object} configuration.android Specifices how verification will start on Android platforms\n * @param {boolean} configuration.android.withForeground Specifices if the foreground service will be turned on to speed up rate of verification, default is true\n * @param {string} fcmPushNotificationToken User's firebase push notification token\n * @returns {Promise<string>} A promise that resolves to a string value of the location identifier\n */\nexport const start = (\n phoneNumber: string,\n locationId: string,\n lat: number,\n lon: number,\n configuration?: OkVerifyStartConfiguration,\n fcmPushNotificationToken?: string\n) => {\n return isValidPlatform(() => {\n if (Platform.OS === 'android') {\n return OkHiNativeModule.startAddressVerification(\n phoneNumber,\n locationId,\n lat,\n lon,\n configuration,\n fcmPushNotificationToken\n );\n } else {\n return OkHiNativeModule.startAddressVerification(\n phoneNumber,\n locationId,\n lat,\n lon\n );\n }\n });\n};\n\n/**\n * Starts verification for a particular address using the response object returned by OkCollect\n * @param {Object} response Response returned by OkCollect\n * @param {Object} configuration Configures how verification will start on different platforms\n * @param {Object} configuration.android Specifices how verification will start on Android platforms\n * @param {boolean} configuration.android.withForeground Specifices if the foreground service will be turned on to speed up rate of verification\n * @returns {Promise<string>} A promise that resolves to a string value of the location identifier\n */\nexport const startVerification = async (\n response: OkCollectSuccessResponse,\n configuration?: OkVerifyStartConfiguration\n) => {\n return new Promise((resolve, reject) => {\n const { location, user } = response;\n if (location.id) {\n if (Platform.OS === 'android') {\n const result = OkHiNativeModule.startAddressVerification(\n user.phone,\n location.id,\n location.lat,\n location.lon,\n configuration,\n user.fcmPushNotificationToken\n );\n resolve(result);\n } else {\n const result = OkHiNativeModule.startAddressVerification(\n user.phone,\n location.id,\n location.lat,\n location.lon\n );\n resolve(result);\n }\n } else {\n reject(\n new OkHiException({\n code: OkHiException.BAD_REQUEST_CODE,\n message: 'Missing location id from response',\n })\n );\n }\n });\n};\n\n/**\n * Stops verification for a particular address using a user's phonenumber and OkHi location identifier\n * @param {string} phoneNumber The user's phone number\n * @param {string} locationId An OkHi location identifier obtained after successfull creation of addresses.\n * @returns {Promise<string>} A promise that resolves to a string value of the location identifier\n */\nexport const stopVerification = (phoneNumber: string, locationId: string) => {\n return isValidPlatform(() =>\n OkHiNativeModule.stopAddressVerification(phoneNumber, locationId)\n );\n};\n\n/**\n * Android Only - Starts a foreground service that speeds up rate of verification\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service has started successfully\n */\nexport const startForegroundService = () => {\n return isValidPlatform(\n () => errorHandler(OkHiNativeModule.startForegroundService),\n 'android'\n );\n};\n\n/**\n * Android Only - Stops previously started foreground services\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service has stopped successfully\n */\nexport const stopForegroundService = () => {\n return isValidPlatform(OkHiNativeModule.stopForegroundService, 'android');\n};\n\n/**\n * Android Only - Checks if the foreground service is running\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service is running\n */\nexport const isForegroundServiceRunning = () => {\n return isValidPlatform(\n OkHiNativeModule.isForegroundServiceRunning,\n 'android'\n );\n};\n\n/**\n * Checks whether all necessary permissions and services are available in order to start the address verification process\n * @param {Object} configuration Object that determines whether or not to request these permissions and services from the user\n * @param {boolean} configuration.requestServices Flag that determines whether to request the services from the user\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether or not all conditions are met to start the address verification process\n */\nexport const canStartVerification = (configuration?: {\n requestServices?: boolean;\n}): Promise<boolean> => {\n return new Promise(async (resolve, reject) => {\n const requestServices = configuration && configuration.requestServices;\n const locationServicesStatus = await isLocationServicesEnabled();\n const googlePlayServices =\n Platform.OS === 'android' ? await isGooglePlayServicesAvailable() : true;\n const backgroundLocationPerm =\n await isBackgroundLocationPermissionGranted();\n const whenInUseLocationPerm = await isLocationPermissionGranted();\n if (!requestServices) {\n resolve(\n locationServicesStatus && googlePlayServices && backgroundLocationPerm\n );\n return;\n }\n if (Platform.OS === 'ios') {\n if (!locationServicesStatus) {\n reject(\n new OkHiException({\n code: OkHiException.SERVICE_UNAVAILABLE_CODE,\n message: 'Location services is unavailable',\n })\n );\n return;\n }\n if (backgroundLocationPerm) {\n resolve(true);\n return;\n }\n if (whenInUseLocationPerm && !backgroundLocationPerm) {\n resolve(false);\n return;\n }\n const iosPerm = await requestBackgroundLocationPermission();\n resolve(iosPerm);\n return;\n } else if (Platform.OS === 'android') {\n const locationServicesRequestStatus =\n (await requestEnableLocationServices()) as boolean;\n const gPlayServices = await requestEnableGooglePlayServices();\n const androidPerm =\n (await requestLocationPermission()) &&\n (await requestBackgroundLocationPermission());\n resolve(locationServicesRequestStatus && gPlayServices && androidPerm);\n } else {\n reject(\n new OkHiException({\n code: OkHiException.UNSUPPORTED_PLATFORM_CODE,\n message: OkHiException.UNSUPPORTED_PLATFORM_MESSAGE,\n })\n );\n }\n });\n};\n\n/**\n * Checks whether all necessary permissions and services are available in order to start the address verification process\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether or not all conditions are met to start the address verification process\n */\nexport const checkVerificationStartRequirements = (): Promise<boolean> => {\n return new Promise(async (resolve, reject) => {\n if (Platform.OS === 'android') {\n const isPlayServicesAvailable = await isGooglePlayServicesAvailable();\n if (!isPlayServicesAvailable) {\n reject(\n new OkHiException({\n code: OkHiException.PLAY_SERVICES_UNAVAILABLE_CODE,\n message: 'Google Play Services is unavailable',\n })\n );\n return;\n }\n }\n if (!(await isLocationServicesEnabled())) {\n reject(\n new OkHiException({\n code: OkHiException.LOCATION_SERVICES_UNAVAILABLE_CODE,\n message: 'Location services unavailable',\n })\n );\n return;\n }\n if (!(await isBackgroundLocationPermissionGranted())) {\n reject(\n new OkHiException({\n code: OkHiException.PERMISSION_DENIED_CODE,\n message: 'Background Location permission not granted',\n })\n );\n return;\n }\n resolve(true);\n });\n};\n\n/**\n * Android Only - Updates user's device firebase push notification token\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service has started successfully\n */\nexport const onNewToken = (fcmPushNotificationToken: string) => {\n if (Platform.OS === 'android') {\n return OkHiNativeModule.onNewToken(fcmPushNotificationToken);\n }\n return Promise.resolve(true);\n};\n\n/**\n * Android Only - Should be invoked only when push notification is received.\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service has started successfully\n */\nexport const onMessageReceived = () => {\n if (Platform.OS === 'android') {\n return OkHiNativeModule.onMessageReceived();\n }\n return Promise.resolve(true);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AAUA;;AACA;;AAGA;;AACA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAA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AhB,CAAP;AACD,CALM;AAOP;AACA;AACA;AACA;;;;;AACO,MAAM4C,iBAAiB,GAAG,MAAM;EACrC,IAAInD,qBAAA,CAASC,EAAT,KAAgB,SAApB,EAA+B;IAC7B,OAAOC,kCAAA,CAAiBiD,iBAAjB,EAAP;EACD;;EACD,OAAO7C,OAAO,CAACC,OAAR,CAAgB,IAAhB,CAAP;AACD,CALM"}
@@ -1,13 +1,19 @@
1
- import { canOpenProtectedAppsSettings, isBackgroundLocationPermissionGranted, isLocationPermissionGranted } from '../OkCore';
1
+ import { canOpenProtectedAppsSettings, isBackgroundLocationPermissionGranted, isLocationPermissionGranted, OkHiException } from '../OkCore';
2
2
  import { OkHiMode } from '../OkCore';
3
3
  import manifest from './app.json'; //TODO: fix this
4
4
 
5
5
  import { Platform } from 'react-native';
6
6
  import { OkHiNativeModule } from '../OkHiNativeModule';
7
+
8
+ const fetchCurrentLocation = async () => {
9
+ const result = await OkHiNativeModule.fetchCurrentLocation();
10
+ return result;
11
+ };
7
12
  /**
8
13
  * @ignore
9
14
  */
10
15
 
16
+
11
17
  export const generateStartDataPayload = async (props, authToken, applicationConfiguration) => {
12
18
  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;
13
19
 
@@ -44,29 +50,64 @@ export const generateStartDataPayload = async (props, authToken, applicationConf
44
50
  name: 'react-native'
45
51
  }
46
52
  };
47
- let hasLocationPermission;
53
+ payload.config = {
54
+ streetView: typeof ((_props$config = props.config) === null || _props$config === void 0 ? void 0 : _props$config.streetView) === 'boolean' ? props.config.streetView : true,
55
+ appBar: {
56
+ color: (_props$theme3 = props.theme) === null || _props$theme3 === void 0 ? void 0 : (_props$theme3$appBar = _props$theme3.appBar) === null || _props$theme3$appBar === void 0 ? void 0 : _props$theme3$appBar.backgroundColor,
57
+ visible: (_props$config2 = props.config) === null || _props$config2 === void 0 ? void 0 : (_props$config2$appBar = _props$config2.appBar) === null || _props$config2$appBar === void 0 ? void 0 : _props$config2$appBar.visible
58
+ },
59
+ addressTypes: {
60
+ 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,
61
+ 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
62
+ },
63
+ protectedApps: Platform.OS === 'android' && (await canOpenProtectedAppsSettings())
64
+ };
48
65
 
49
- try {
50
- hasLocationPermission = await isLocationPermissionGranted();
51
- } catch (error) {
52
- console.log(error);
53
- }
66
+ if (Platform.OS === 'ios') {
67
+ const status = await OkHiNativeModule.fetchIOSLocationPermissionStatus();
68
+
69
+ if (status !== 'notDetermined') {
70
+ payload.context.permissions = {
71
+ location: status === 'authorizedWhenInUse' ? 'whenInUse' : status === 'authorizedAlways' || status === 'authorized' ? 'always' : 'denided'
72
+ };
73
+
74
+ if (status === 'authorized' || status === 'authorizedWhenInUse' || status === 'authorizedAlways') {
75
+ const location = await fetchCurrentLocation();
76
+
77
+ if (location) {
78
+ payload.context.coordinates = {
79
+ currentLocation: {
80
+ lat: location.lat,
81
+ lng: location.lng,
82
+ accuracy: location.accuracy
83
+ }
84
+ };
85
+ }
86
+ }
87
+ }
88
+ } else if (Platform.OS === 'android') {
89
+ let hasLocationPermission;
90
+
91
+ try {
92
+ hasLocationPermission = await isLocationPermissionGranted();
93
+ } catch (error) {
94
+ console.log(error);
95
+ }
54
96
 
55
- let hasBackgroundLocationPermission;
97
+ let hasBackgroundLocationPermission;
56
98
 
57
- try {
58
- hasBackgroundLocationPermission = await isBackgroundLocationPermissionGranted();
59
- } catch (error) {
60
- console.log(error);
61
- }
99
+ try {
100
+ hasBackgroundLocationPermission = await isBackgroundLocationPermissionGranted();
101
+ } catch (error) {
102
+ console.log(error);
103
+ }
62
104
 
63
- if (typeof hasLocationPermission === 'boolean' && typeof hasBackgroundLocationPermission === 'boolean') {
64
- payload.context.permissions = {
65
- location: hasBackgroundLocationPermission ? 'always' : hasLocationPermission ? 'whenInUse' : 'denied'
66
- };
67
- }
105
+ if (typeof hasLocationPermission === 'boolean' && typeof hasBackgroundLocationPermission === 'boolean') {
106
+ payload.context.permissions = {
107
+ location: hasBackgroundLocationPermission ? 'always' : hasLocationPermission ? 'whenInUse' : 'denied'
108
+ };
109
+ }
68
110
 
69
- if (Platform.OS === 'android') {
70
111
  const {
71
112
  manufacturer,
72
113
  model
@@ -75,22 +116,13 @@ export const generateStartDataPayload = async (props, authToken, applicationConf
75
116
  manufacturer,
76
117
  model
77
118
  };
78
- payload.context.permissions = { ...payload.context.permissions
79
- };
119
+ } else {
120
+ throw new OkHiException({
121
+ code: OkHiException.UNSUPPORTED_PLATFORM_CODE,
122
+ message: OkHiException.UNAUTHORIZED_MESSAGE
123
+ });
80
124
  }
81
125
 
82
- payload.config = {
83
- protectedApps: Platform.OS === 'android' && (await canOpenProtectedAppsSettings()),
84
- streetView: typeof ((_props$config = props.config) === null || _props$config === void 0 ? void 0 : _props$config.streetView) === 'boolean' ? props.config.streetView : true,
85
- appBar: {
86
- color: (_props$theme3 = props.theme) === null || _props$theme3 === void 0 ? void 0 : (_props$theme3$appBar = _props$theme3.appBar) === null || _props$theme3$appBar === void 0 ? void 0 : _props$theme3$appBar.backgroundColor,
87
- visible: (_props$config2 = props.config) === null || _props$config2 === void 0 ? void 0 : (_props$config2$appBar = _props$config2.appBar) === null || _props$config2$appBar === void 0 ? void 0 : _props$config2$appBar.visible
88
- },
89
- addressTypes: {
90
- 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,
91
- 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
92
- }
93
- };
94
126
  return payload;
95
127
  };
96
128
  /**
@@ -1 +1 @@
1
- {"version":3,"names":["canOpenProtectedAppsSettings","isBackgroundLocationPermissionGranted","isLocationPermissionGranted","OkHiMode","manifest","Platform","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","platform","hasLocationPermission","error","console","log","hasBackgroundLocationPermission","permissions","location","OS","manufacturer","model","retrieveDeviceInfo","device","config","protectedApps","streetView","backgroundColor","visible","addressTypes","home","work","getFrameUrl","DEV_FRAME_URL","PROD_FRAME_URL","SANDBOX_FRAME_URL","LEGACY_DEV_FRAME_URL","LEGACY_PROD_FRAME_URL","LEGACY_SANDBOX_FRAME_URL","Version","mode","PROD","generateJavaScriptStartScript","startPayload","jsBeforeLoad","JSON","stringify","jsAfterLoad","parseOkHiLocation","id","lat","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 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\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\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\n if (Platform.OS === 'android') {\n const { manufacturer, model } = await OkHiNativeModule.retrieveDeviceInfo();\n payload.context.device = {\n manufacturer,\n model,\n };\n payload.context.permissions = {\n ...payload.context.permissions,\n };\n }\n payload.config = {\n protectedApps:\n Platform.OS === 'android' && (await canOpenProtectedAppsSettings()),\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 };\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,SACEA,4BADF,EAEEC,qCAFF,EAGEC,2BAHF,QAKO,WALP;AAMA,SAASC,QAAT,QAAyB,WAAzB;AAKA,OAAOC,QAAP,MAAqB,YAArB,C,CAAmC;;AAEnC,SAASC,QAAT,QAAyB,cAAzB;AACA,SAASC,gBAAT,QAAiC,qBAAjC;AAEA;AACA;AACA;;AACA,OAAO,MAAMC,wBAAwB,GAAG,OACtCC,KADsC,EAEtCC,SAFsC,EAGtCC,wBAHsC,KAIW;EAAA;;EACjD,MAAMC,OAAY,GAAG,EAArB;EACAA,OAAO,CAACC,KAAR,GAAgB,CAACJ,KAAK,CAACK,KAAP,GACZC,SADY,GAEZ;IACEC,IAAI,EAAE;MACJC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AQ,CAAEgD,GAZV;IAaLC,gBAAgB,EAAEjD,QAAF,aAAEA,QAAF,gDAAEA,QAAQ,CAAEkD,WAAZ,0DAAE,sBAAuBC,OAbpC;IAcLC,iBAAiB,EAAEpD,QAAF,aAAEA,QAAF,iDAAEA,QAAQ,CAAEkD,WAAZ,2DAAE,uBAAuBF,GAdrC;IAeLK,MAAM,EAAErD,QAAF,aAAEA,QAAF,uBAAEA,QAAQ,CAAEsD,OAfb;IAgBLC,cAAc,EAAEvD,QAAF,aAAEA,QAAF,uBAAEA,QAAQ,CAAEuD,cAhBrB;IAiBLC,KAAK,EAAExD,QAAF,aAAEA,QAAF,uBAAEA,QAAQ,CAAEwD,KAjBZ;IAkBLC,YAAY,EAAEzD,QAAF,aAAEA,QAAF,uBAAEA,QAAQ,CAAE0D,aAlBnB;IAmBLC,OAAO,EAAE3D,QAAF,aAAEA,QAAF,uBAAEA,QAAQ,CAAE2D,OAnBd;IAoBLC,KAAK,EAAE5D,QAAF,aAAEA,QAAF,uBAAEA,QAAQ,CAAE4D,KApBZ;IAqBLC,IAAI,EAAE7D,QAAF,aAAEA,QAAF,uBAAEA,QAAQ,CAAE6D,IArBX;IAsBLC,WAAW,EAAE9D,QAAF,aAAEA,QAAF,uBAAEA,QAAQ,CAAE+D;EAtBlB,CAAP;AAwBD,CAzBM"}
1
+ {"version":3,"names":["canOpenProtectedAppsSettings","isBackgroundLocationPermissionGranted","isLocationPermissionGranted","OkHiException","OkHiMode","manifest","Platform","OkHiNativeModule","fetchCurrentLocation","result","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","platform","config","streetView","backgroundColor","visible","addressTypes","home","work","protectedApps","OS","status","fetchIOSLocationPermissionStatus","permissions","location","coordinates","currentLocation","lat","lng","accuracy","hasLocationPermission","error","console","log","hasBackgroundLocationPermission","manufacturer","model","retrieveDeviceInfo","device","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","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,SACEA,4BADF,EAEEC,qCAFF,EAGEC,2BAHF,EAIEC,aAJF,QAMO,WANP;AAOA,SAASC,QAAT,QAAyB,WAAzB;AAKA,OAAOC,QAAP,MAAqB,YAArB,C,CAAmC;;AAEnC,SAASC,QAAT,QAAyB,cAAzB;AACA,SAASC,gBAAT,QAAiC,qBAAjC;;AAEA,MAAMC,oBAAoB,GAAG,YAIvB;EACJ,MAAMC,MAAM,GAAG,MAAMF,gBAAgB,CAACC,oBAAjB,EAArB;EACA,OAAOC,MAAP;AACD,CAPD;AASA;AACA;AACA;;;AACA,OAAO,MAAMC,wBAAwB,GAAG,OACtCC,KADsC,EAEtCC,SAFsC,EAGtCC,wBAHsC,KAIW;EAAA;;EACjD,MAAMC,OAAY,GAAG,EAArB;EACAA,OAAO,CAACC,KAAR,GAAgB,CAACJ,KAAK,CAACK,KAAP,GACZC,SADY,GAEZ;IACEC,IAAI,EAAE;MACJC,KAAK,kBAAER,KAAK,CAACK,KAAR,wEAAE,aAAaI,MAAf,wDAAE,oBAAqBC,OADxB;MAEJC,IAAI,mBAAEX,KAAK,CAACK,KAAR,0EAAE,cAAaO,MAAf,yDAAE,qBAAqBD,IAFvB;MAGJE,IAAI,2BAAEX,wBAAwB,CAACY,GAA3B,0DAAE,sBAA8BD;IAHhC;EADR,CAFJ;EASAV,OAAO,CAACY,IAAR,GAAe;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AQ,CAAEiE,IArBX;IAsBLC,WAAW,EAAElE,QAAF,aAAEA,QAAF,uBAAEA,QAAQ,CAAEmE;EAtBlB,CAAP;AAwBD,CAzBM"}
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "okhiWebReactNative",
3
- "version": "1.1.2"
3
+ "version": "1.1.3-beta.1"
4
4
  }
@@ -5,6 +5,7 @@ import { OkHiMode } from './OkHiMode';
5
5
  import { OkHiException } from './OkHiException';
6
6
  import { getApplicationConfiguration } from './';
7
7
  import { OkHiNativeModule } from '../OkHiNativeModule';
8
+ import { Platform } from 'react-native';
8
9
  /**
9
10
  * @ignore
10
11
  */
@@ -72,7 +73,10 @@ export class OkHiAuth {
72
73
  } = await axios.post(url, payload, {
73
74
  headers
74
75
  });
75
- await OkHiNativeModule.setItem('okhi:recent:token', data.authorization_token); //TODO: move all anonymousSignIn to native code
76
+
77
+ if (Platform.OS === 'android') {
78
+ await OkHiNativeModule.setItem('okhi:recent:token', data.authorization_token); //TODO: move all anonymousSignIn to native code
79
+ }
76
80
 
77
81
  resolve(data.authorization_token);
78
82
  }
@@ -1 +1 @@
1
- {"version":3,"names":["axios","OkHiMode","OkHiException","getApplicationConfiguration","OkHiNativeModule","OkHiAuth","API_VERSION","ANONYMOUS_SIGN_IN_ENDPOINT","anonymousSignInWithPhoneNumber","phone","scopes","config","anonymousSignIn","anonymousSignInWithUserId","userId","user_id","payload","Promise","resolve","reject","auth","token","code","UNAUTHORIZED_CODE","message","UNAUTHORIZED_MESSAGE","context","url","SANDBOX_BASE_URL","mode","DEV_BASE_URL","PROD","PROD_BASE_URL","headers","Authorization","data","post","setItem","authorization_token","error","parseRequestError","response","NETWORK_ERROR_CODE","NETWORK_ERROR_MESSAGE","status","INVALID_PHONE_CODE","INVALID_PHONE_MESSAGE","UNKNOWN_ERROR_CODE","UNKNOWN_ERROR_MESSAGE"],"sources":["OkHiAuth.ts"],"sourcesContent":["import axios from 'axios';\nimport { OkHiMode } from './OkHiMode';\nimport { OkHiException } from './OkHiException';\nimport type { AuthApplicationConfig, OkHiAccessScope } from './_types';\nimport { getApplicationConfiguration } from './';\nimport { OkHiNativeModule } from '../OkHiNativeModule';\n\n/**\n * @ignore\n */\nexport class OkHiAuth {\n private readonly API_VERSION = 'v5';\n private readonly ANONYMOUS_SIGN_IN_ENDPOINT = '/auth/anonymous-signin';\n private readonly DEV_BASE_URL =\n `https://dev-api.okhi.io/${this.API_VERSION}` +\n this.ANONYMOUS_SIGN_IN_ENDPOINT;\n private readonly SANDBOX_BASE_URL =\n `https://sandbox-api.okhi.io/${this.API_VERSION}` +\n this.ANONYMOUS_SIGN_IN_ENDPOINT;\n private readonly PROD_BASE_URL =\n `https://api.okhi.io/${this.API_VERSION}` + this.ANONYMOUS_SIGN_IN_ENDPOINT;\n private config: AuthApplicationConfig | null = null;\n\n anonymousSignInWithPhoneNumber(\n phone: string,\n scopes: Array<OkHiAccessScope>,\n config: AuthApplicationConfig\n ) {\n this.config = config;\n return this.anonymousSignIn({\n scopes,\n phone,\n });\n }\n\n protected anonymousSignInWithUserId(\n userId: string,\n scopes: Array<OkHiAccessScope>\n ) {\n return this.anonymousSignIn({\n scopes,\n user_id: userId,\n });\n }\n\n private async anonymousSignIn(payload: {\n scopes: Array<OkHiAccessScope>;\n [key: string]: any;\n }): Promise<string> {\n return new Promise(async (resolve, reject) => {\n try {\n const config = this.config || (await getApplicationConfiguration());\n if (config === null || !config.auth || !config.auth.token) {\n reject(\n new OkHiException({\n code: OkHiException.UNAUTHORIZED_CODE,\n message: OkHiException.UNAUTHORIZED_MESSAGE,\n })\n );\n } else {\n const { auth, context } = config;\n let url = this.SANDBOX_BASE_URL;\n if (context?.mode === ('dev' as any)) {\n url = this.DEV_BASE_URL;\n } else if (context?.mode === OkHiMode.PROD) {\n url = this.PROD_BASE_URL;\n } else {\n url = this.SANDBOX_BASE_URL;\n }\n const headers = { Authorization: auth.token };\n const { data } = await axios.post(url, payload, {\n headers,\n });\n await OkHiNativeModule.setItem(\n 'okhi:recent:token',\n data.authorization_token\n ); //TODO: move all anonymousSignIn to native code\n resolve(data.authorization_token);\n }\n } catch (error) {\n reject(this.parseRequestError(error));\n }\n });\n }\n\n private parseRequestError(error: any) {\n if (!error.response) {\n return new OkHiException({\n code: OkHiException.NETWORK_ERROR_CODE,\n message: OkHiException.NETWORK_ERROR_MESSAGE,\n });\n }\n switch (error.response.status) {\n case 400:\n return new OkHiException({\n code: OkHiException.INVALID_PHONE_CODE,\n message: OkHiException.INVALID_PHONE_MESSAGE,\n });\n case 401:\n return new OkHiException({\n code: OkHiException.UNAUTHORIZED_CODE,\n message: OkHiException.UNAUTHORIZED_MESSAGE,\n });\n default:\n return new OkHiException({\n code: OkHiException.UNKNOWN_ERROR_CODE,\n message: error.message || OkHiException.UNKNOWN_ERROR_MESSAGE,\n });\n }\n }\n}\n"],"mappings":";;AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,SAASC,QAAT,QAAyB,YAAzB;AACA,SAASC,aAAT,QAA8B,iBAA9B;AAEA,SAASC,2BAAT,QAA4C,IAA5C;AACA,SAASC,gBAAT,QAAiC,qBAAjC;AAEA;AACA;AACA;;AACA,OAAO,MAAMC,QAAN,CAAe;EAAA;IAAA,qCACW,IADX;;IAAA,oDAE0B,wBAF1B;;IAAA,sCAIjB,2BAA0B,KAAKC,WAAY,EAA5C,GACA,KAAKC,0BALa;;IAAA,0CAOjB,+BAA8B,KAAKD,WAAY,EAAhD,GACA,KAAKC,0BARa;;IAAA,uCAUjB,uBAAsB,KAAKD,WAAY,EAAxC,GAA4C,KAAKC,0BAV/B;;IAAA,gCAW2B,IAX3B;EAAA;;EAapBC,8BAA8B,CAC5BC,KAD4B,EAE5BC,MAF4B,EAG5BC,MAH4B,EAI5B;IACA,KAAKA,MAAL,GAAcA,MAAd;IACA,OAAO,KAAKC,eAAL,CAAqB;MAC1BF,MAD0B;MAE1BD;IAF0B,CAArB,CAAP;EAID;;EAESI,yBAAyB,CACjCC,MADiC,EAEjCJ,M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,gBAAgB,CAACiC,OAAjB,CACJ,mBADI,EAEJF,IAAI,CAACG,mBAFD,CAAN,CAdK,CAiBF;;UACHpB,OAAO,CAACiB,IAAI,CAACG,mBAAN,CAAP;QACD;MACF,CA7BD,CA6BE,OAAOC,KAAP,EAAc;QACdpB,MAAM,CAAC,KAAKqB,iBAAL,CAAuBD,KAAvB,CAAD,CAAN;MACD;IACF,CAjCM,CAAP;EAkCD;;EAEOC,iBAAiB,CAACD,KAAD,EAAa;IACpC,IAAI,CAACA,KAAK,CAACE,QAAX,EAAqB;MACnB,OAAO,IAAIvC,aAAJ,CAAkB;QACvBoB,IAAI,EAAEpB,aAAa,CAACwC,kBADG;QAEvBlB,OAAO,EAAEtB,aAAa,CAACyC;MAFA,CAAlB,CAAP;IAID;;IACD,QAAQJ,KAAK,CAACE,QAAN,CAAeG,MAAvB;MACE,KAAK,GAAL;QACE,OAAO,IAAI1C,aAAJ,CAAkB;UACvBoB,IAAI,EAAEpB,aAAa,CAAC2C,kBADG;UAEvBrB,OAAO,EAAEtB,aAAa,CAAC4C;QAFA,CAAlB,CAAP;;MAIF,KAAK,GAAL;QACE,OAAO,IAAI5C,aAAJ,CAAkB;UACvBoB,IAAI,EAAEpB,aAAa,CAACqB,iBADG;UAEvBC,OAAO,EAAEtB,aAAa,CAACuB;QAFA,CAAlB,CAAP;;MAIF;QACE,OAAO,IAAIvB,aAAJ,CAAkB;UACvBoB,IAAI,EAAEpB,aAAa,CAAC6C,kBADG;UAEvBvB,OAAO,EAAEe,KAAK,CAACf,OAAN,IAAiBtB,aAAa,CAAC8C;QAFjB,CAAlB,CAAP;IAZJ;EAiBD;;AAnGmB"}
1
+ {"version":3,"names":["axios","OkHiMode","OkHiException","getApplicationConfiguration","OkHiNativeModule","Platform","OkHiAuth","API_VERSION","ANONYMOUS_SIGN_IN_ENDPOINT","anonymousSignInWithPhoneNumber","phone","scopes","config","anonymousSignIn","anonymousSignInWithUserId","userId","user_id","payload","Promise","resolve","reject","auth","token","code","UNAUTHORIZED_CODE","message","UNAUTHORIZED_MESSAGE","context","url","SANDBOX_BASE_URL","mode","DEV_BASE_URL","PROD","PROD_BASE_URL","headers","Authorization","data","post","OS","setItem","authorization_token","error","parseRequestError","response","NETWORK_ERROR_CODE","NETWORK_ERROR_MESSAGE","status","INVALID_PHONE_CODE","INVALID_PHONE_MESSAGE","UNKNOWN_ERROR_CODE","UNKNOWN_ERROR_MESSAGE"],"sources":["OkHiAuth.ts"],"sourcesContent":["import axios from 'axios';\nimport { OkHiMode } from './OkHiMode';\nimport { OkHiException } from './OkHiException';\nimport type { AuthApplicationConfig, OkHiAccessScope } from './_types';\nimport { getApplicationConfiguration } from './';\nimport { OkHiNativeModule } from '../OkHiNativeModule';\nimport { Platform } from 'react-native';\n\n/**\n * @ignore\n */\nexport class OkHiAuth {\n private readonly API_VERSION = 'v5';\n private readonly ANONYMOUS_SIGN_IN_ENDPOINT = '/auth/anonymous-signin';\n private readonly DEV_BASE_URL =\n `https://dev-api.okhi.io/${this.API_VERSION}` +\n this.ANONYMOUS_SIGN_IN_ENDPOINT;\n private readonly SANDBOX_BASE_URL =\n `https://sandbox-api.okhi.io/${this.API_VERSION}` +\n this.ANONYMOUS_SIGN_IN_ENDPOINT;\n private readonly PROD_BASE_URL =\n `https://api.okhi.io/${this.API_VERSION}` + this.ANONYMOUS_SIGN_IN_ENDPOINT;\n private config: AuthApplicationConfig | null = null;\n\n anonymousSignInWithPhoneNumber(\n phone: string,\n scopes: Array<OkHiAccessScope>,\n config: AuthApplicationConfig\n ) {\n this.config = config;\n return this.anonymousSignIn({\n scopes,\n phone,\n });\n }\n\n protected anonymousSignInWithUserId(\n userId: string,\n scopes: Array<OkHiAccessScope>\n ) {\n return this.anonymousSignIn({\n scopes,\n user_id: userId,\n });\n }\n\n private async anonymousSignIn(payload: {\n scopes: Array<OkHiAccessScope>;\n [key: string]: any;\n }): Promise<string> {\n return new Promise(async (resolve, reject) => {\n try {\n const config = this.config || (await getApplicationConfiguration());\n if (config === null || !config.auth || !config.auth.token) {\n reject(\n new OkHiException({\n code: OkHiException.UNAUTHORIZED_CODE,\n message: OkHiException.UNAUTHORIZED_MESSAGE,\n })\n );\n } else {\n const { auth, context } = config;\n let url = this.SANDBOX_BASE_URL;\n if (context?.mode === ('dev' as any)) {\n url = this.DEV_BASE_URL;\n } else if (context?.mode === OkHiMode.PROD) {\n url = this.PROD_BASE_URL;\n } else {\n url = this.SANDBOX_BASE_URL;\n }\n const headers = { Authorization: auth.token };\n const { data } = await axios.post(url, payload, {\n headers,\n });\n if (Platform.OS === 'android') {\n await OkHiNativeModule.setItem(\n 'okhi:recent:token',\n data.authorization_token\n ); //TODO: move all anonymousSignIn to native code\n }\n resolve(data.authorization_token);\n }\n } catch (error) {\n reject(this.parseRequestError(error));\n }\n });\n }\n\n private parseRequestError(error: any) {\n if (!error.response) {\n return new OkHiException({\n code: OkHiException.NETWORK_ERROR_CODE,\n message: OkHiException.NETWORK_ERROR_MESSAGE,\n });\n }\n switch (error.response.status) {\n case 400:\n return new OkHiException({\n code: OkHiException.INVALID_PHONE_CODE,\n message: OkHiException.INVALID_PHONE_MESSAGE,\n });\n case 401:\n return new OkHiException({\n code: OkHiException.UNAUTHORIZED_CODE,\n message: OkHiException.UNAUTHORIZED_MESSAGE,\n });\n default:\n return new OkHiException({\n code: OkHiException.UNKNOWN_ERROR_CODE,\n message: error.message || OkHiException.UNKNOWN_ERROR_MESSAGE,\n });\n }\n }\n}\n"],"mappings":";;AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,SAASC,QAAT,QAAyB,YAAzB;AACA,SAASC,aAAT,QAA8B,iBAA9B;AAEA,SAASC,2BAAT,QAA4C,IAA5C;AACA,SAASC,gBAAT,QAAiC,qBAAjC;AACA,SAASC,QAAT,QAAyB,cAAzB;AAEA;AACA;AACA;;AACA,OAAO,MAAMC,QAAN,CAAe;EAAA;IAAA,qCACW,IADX;;IAAA,oDAE0B,wBAF1B;;IAAA,sCAIjB,2BAA0B,KAA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aAAa,CAACsB,iBADG;UAEvBC,OAAO,EAAEvB,aAAa,CAACwB;QAFA,CAAlB,CAAP;;MAIF;QACE,OAAO,IAAIxB,aAAJ,CAAkB;UACvBqB,IAAI,EAAErB,aAAa,CAAC+C,kBADG;UAEvBxB,OAAO,EAAEgB,KAAK,CAAChB,OAAN,IAAiBvB,aAAa,CAACgD;QAFjB,CAAlB,CAAP;IAZJ;EAiBD;;AArGmB"}
@@ -1 +1 @@
1
- {"version":3,"names":["NativeModules","NativeEventEmitter","Platform","LINKING_ERROR","select","ios","default","OkHiNativeModule","Okhi","Proxy","get","Error","OkHiNativeEvents","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};\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,SAASA,aAAT,EAAwBC,kBAAxB,EAA4CC,QAA5C,QAA4D,cAA5D;AAGA,MAAMC,aAAa,GAChB,4EAAD,GACAD,QAAQ,CAACE,MAAT,CAAgB;EAAEC,GAAG,EAAE,gCAAP;EAAyCC,OAAO,EAAE;AAAlD,CAAhB,CADA,GAEA,sDAFA,GAGA,6CAJF;AAmDA,OAAO,MAAMC,gBAAsC,GAAGP,aAAa,CAACQ,IAAd,GAClDR,aAAa,CAACQ,IADoC,GAElD,IAAIC,KAAJ,CACE,EADF,EAEE;EACEC,GAAG,GAAG;IACJ,MAAM,IAAIC,KAAJ,CAAUR,aAAV,CAAN;EACD;;AAHH,CAFF,CAFG;AAWP,OAAO,MAAMS,gBAAgB,GAAG,IAAIX,kBAAJ,CAAuBD,aAAa,CAACQ,IAArC,CAAzB;AAEPI,gBAAgB,CAACC,WAAjB,CAA6B,kCAA7B,EAAiE,MAAM,IAAvE"}
1
+ {"version":3,"names":["NativeModules","NativeEventEmitter","Platform","LINKING_ERROR","select","ios","default","OkHiNativeModule","Okhi","Proxy","get","Error","OkHiNativeEvents","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,SAASA,aAAT,EAAwBC,kBAAxB,EAA4CC,QAA5C,QAA4D,cAA5D;AAGA,MAAMC,aAAa,GAChB,4EAAD,GACAD,QAAQ,CAACE,MAAT,CAAgB;EAAEC,GAAG,EAAE,gCAAP;EAAyCC,OAAO,EAAE;AAAlD,CAAhB,CADA,GAEA,sDAFA,GAGA,6CAJF;AAiEA,OAAO,MAAMC,gBAAsC,GAAGP,aAAa,CAACQ,IAAd,GAClDR,aAAa,CAACQ,IADoC,GAElD,IAAIC,KAAJ,CACE,EADF,EAEE;EACEC,GAAG,GAAG;IACJ,MAAM,IAAIC,KAAJ,CAAUR,aAAV,CAAN;EACD;;AAHH,CAFF,CAFG;AAWP,OAAO,MAAMS,gBAAgB,GAAG,IAAIX,kBAAJ,CAAuBD,aAAa,CAACQ,IAArC,CAAzB;AAEPI,gBAAgB,CAACC,WAAjB,CAA6B,kCAA7B,EAAiE,MAAM,IAAvE"}
@@ -191,7 +191,11 @@ export const checkVerificationStartRequirements = () => {
191
191
  */
192
192
 
193
193
  export const onNewToken = fcmPushNotificationToken => {
194
- return isValidPlatform(() => errorHandler(() => OkHiNativeModule.onNewToken(fcmPushNotificationToken)), 'android');
194
+ if (Platform.OS === 'android') {
195
+ return OkHiNativeModule.onNewToken(fcmPushNotificationToken);
196
+ }
197
+
198
+ return Promise.resolve(true);
195
199
  };
196
200
  /**
197
201
  * Android Only - Should be invoked only when push notification is received.
@@ -199,6 +203,10 @@ export const onNewToken = fcmPushNotificationToken => {
199
203
  */
200
204
 
201
205
  export const onMessageReceived = () => {
202
- return isValidPlatform(() => errorHandler(OkHiNativeModule.onMessageReceived), 'android');
206
+ if (Platform.OS === 'android') {
207
+ return OkHiNativeModule.onMessageReceived();
208
+ }
209
+
210
+ return Promise.resolve(true);
203
211
  };
204
212
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["Platform","isBackgroundLocationPermissionGranted","isGooglePlayServicesAvailable","isLocationServicesEnabled","requestBackgroundLocationPermission","requestEnableGooglePlayServices","requestEnableLocationServices","requestLocationPermission","isLocationPermissionGranted","errorHandler","isValidPlatform","OkHiNativeModule","OkHiException","start","phoneNumber","locationId","lat","lon","configuration","fcmPushNotificationToken","OS","startAddressVerification","startVerification","response","Promise","resolve","reject","location","user","id","result","phone","code","BAD_REQUEST_CODE","message","stopVerification","stopAddressVerification","startForegroundService","stopForegroundService","isForegroundServiceRunning","canStartVerification","requestServices","locationServicesStatus","googlePlayServices","backgroundLocationPerm","whenInUseLocationPerm","SERVICE_UNAVAILABLE_CODE","iosPerm","locationServicesRequestStatus","gPlayServices","androidPerm","UNSUPPORTED_PLATFORM_CODE","UNSUPPORTED_PLATFORM_MESSAGE","checkVerificationStartRequirements","isPlayServicesAvailable","PLAY_SERVICES_UNAVAILABLE_CODE","LOCATION_SERVICES_UNAVAILABLE_CODE","PERMISSION_DENIED_CODE","onNewToken","onMessageReceived"],"sources":["index.ts"],"sourcesContent":["import { Platform } from 'react-native';\nimport {\n isBackgroundLocationPermissionGranted,\n isGooglePlayServicesAvailable,\n isLocationServicesEnabled,\n requestBackgroundLocationPermission,\n requestEnableGooglePlayServices,\n requestEnableLocationServices,\n requestLocationPermission,\n isLocationPermissionGranted,\n} from '../OkCore/Helpers';\nimport { errorHandler, isValidPlatform } from '../OkCore/_helpers';\nimport { OkHiNativeModule } from '../OkHiNativeModule';\nimport type { OkVerifyStartConfiguration } from './types';\nimport type { OkCollectSuccessResponse } from '../OkCollect/types';\nimport { OkHiException } from '../OkCore/OkHiException';\nexport * from './types';\n/**\n * Starts verification for a particular address\n * @param {string} phoneNumber A users phone number\n * @param {string} locationId An OkHi location identifier obtained after successfull creation of addresses.\n * @param {number} lat The latitude of the created address\n * @param {number} lon The longitude of the created address\n * @param {Object} configuration Configures how verification will start on different platforms\n * @param {Object} configuration.android Specifices how verification will start on Android platforms\n * @param {boolean} configuration.android.withForeground Specifices if the foreground service will be turned on to speed up rate of verification, default is true\n * @param {string} fcmPushNotificationToken User's firebase push notification token\n * @returns {Promise<string>} A promise that resolves to a string value of the location identifier\n */\nexport const start = (\n phoneNumber: string,\n locationId: string,\n lat: number,\n lon: number,\n configuration?: OkVerifyStartConfiguration,\n fcmPushNotificationToken?: string\n) => {\n return isValidPlatform(() => {\n if (Platform.OS === 'android') {\n return OkHiNativeModule.startAddressVerification(\n phoneNumber,\n locationId,\n lat,\n lon,\n configuration,\n fcmPushNotificationToken\n );\n } else {\n return OkHiNativeModule.startAddressVerification(\n phoneNumber,\n locationId,\n lat,\n lon\n );\n }\n });\n};\n\n/**\n * Starts verification for a particular address using the response object returned by OkCollect\n * @param {Object} response Response returned by OkCollect\n * @param {Object} configuration Configures how verification will start on different platforms\n * @param {Object} configuration.android Specifices how verification will start on Android platforms\n * @param {boolean} configuration.android.withForeground Specifices if the foreground service will be turned on to speed up rate of verification\n * @returns {Promise<string>} A promise that resolves to a string value of the location identifier\n */\nexport const startVerification = async (\n response: OkCollectSuccessResponse,\n configuration?: OkVerifyStartConfiguration\n) => {\n return new Promise((resolve, reject) => {\n const { location, user } = response;\n if (location.id) {\n if (Platform.OS === 'android') {\n const result = OkHiNativeModule.startAddressVerification(\n user.phone,\n location.id,\n location.lat,\n location.lon,\n configuration,\n user.fcmPushNotificationToken\n );\n resolve(result);\n } else {\n const result = OkHiNativeModule.startAddressVerification(\n user.phone,\n location.id,\n location.lat,\n location.lon\n );\n resolve(result);\n }\n } else {\n reject(\n new OkHiException({\n code: OkHiException.BAD_REQUEST_CODE,\n message: 'Missing location id from response',\n })\n );\n }\n });\n};\n\n/**\n * Stops verification for a particular address using a user's phonenumber and OkHi location identifier\n * @param {string} phoneNumber The user's phone number\n * @param {string} locationId An OkHi location identifier obtained after successfull creation of addresses.\n * @returns {Promise<string>} A promise that resolves to a string value of the location identifier\n */\nexport const stopVerification = (phoneNumber: string, locationId: string) => {\n return isValidPlatform(() =>\n OkHiNativeModule.stopAddressVerification(phoneNumber, locationId)\n );\n};\n\n/**\n * Android Only - Starts a foreground service that speeds up rate of verification\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service has started successfully\n */\nexport const startForegroundService = () => {\n return isValidPlatform(\n () => errorHandler(OkHiNativeModule.startForegroundService),\n 'android'\n );\n};\n\n/**\n * Android Only - Stops previously started foreground services\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service has stopped successfully\n */\nexport const stopForegroundService = () => {\n return isValidPlatform(OkHiNativeModule.stopForegroundService, 'android');\n};\n\n/**\n * Android Only - Checks if the foreground service is running\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service is running\n */\nexport const isForegroundServiceRunning = () => {\n return isValidPlatform(\n OkHiNativeModule.isForegroundServiceRunning,\n 'android'\n );\n};\n\n/**\n * Checks whether all necessary permissions and services are available in order to start the address verification process\n * @param {Object} configuration Object that determines whether or not to request these permissions and services from the user\n * @param {boolean} configuration.requestServices Flag that determines whether to request the services from the user\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether or not all conditions are met to start the address verification process\n */\nexport const canStartVerification = (configuration?: {\n requestServices?: boolean;\n}): Promise<boolean> => {\n return new Promise(async (resolve, reject) => {\n const requestServices = configuration && configuration.requestServices;\n const locationServicesStatus = await isLocationServicesEnabled();\n const googlePlayServices =\n Platform.OS === 'android' ? await isGooglePlayServicesAvailable() : true;\n const backgroundLocationPerm =\n await isBackgroundLocationPermissionGranted();\n const whenInUseLocationPerm = await isLocationPermissionGranted();\n if (!requestServices) {\n resolve(\n locationServicesStatus && googlePlayServices && backgroundLocationPerm\n );\n return;\n }\n if (Platform.OS === 'ios') {\n if (!locationServicesStatus) {\n reject(\n new OkHiException({\n code: OkHiException.SERVICE_UNAVAILABLE_CODE,\n message: 'Location services is unavailable',\n })\n );\n return;\n }\n if (backgroundLocationPerm) {\n resolve(true);\n return;\n }\n if (whenInUseLocationPerm && !backgroundLocationPerm) {\n resolve(false);\n return;\n }\n const iosPerm = await requestBackgroundLocationPermission();\n resolve(iosPerm);\n return;\n } else if (Platform.OS === 'android') {\n const locationServicesRequestStatus =\n (await requestEnableLocationServices()) as boolean;\n const gPlayServices = await requestEnableGooglePlayServices();\n const androidPerm =\n (await requestLocationPermission()) &&\n (await requestBackgroundLocationPermission());\n resolve(locationServicesRequestStatus && gPlayServices && androidPerm);\n } else {\n reject(\n new OkHiException({\n code: OkHiException.UNSUPPORTED_PLATFORM_CODE,\n message: OkHiException.UNSUPPORTED_PLATFORM_MESSAGE,\n })\n );\n }\n });\n};\n\n/**\n * Checks whether all necessary permissions and services are available in order to start the address verification process\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether or not all conditions are met to start the address verification process\n */\nexport const checkVerificationStartRequirements = (): Promise<boolean> => {\n return new Promise(async (resolve, reject) => {\n if (Platform.OS === 'android') {\n const isPlayServicesAvailable = await isGooglePlayServicesAvailable();\n if (!isPlayServicesAvailable) {\n reject(\n new OkHiException({\n code: OkHiException.PLAY_SERVICES_UNAVAILABLE_CODE,\n message: 'Google Play Services is unavailable',\n })\n );\n return;\n }\n }\n if (!(await isLocationServicesEnabled())) {\n reject(\n new OkHiException({\n code: OkHiException.LOCATION_SERVICES_UNAVAILABLE_CODE,\n message: 'Location services unavailable',\n })\n );\n return;\n }\n if (!(await isBackgroundLocationPermissionGranted())) {\n reject(\n new OkHiException({\n code: OkHiException.PERMISSION_DENIED_CODE,\n message: 'Background Location permission not granted',\n })\n );\n return;\n }\n resolve(true);\n });\n};\n\n/**\n * Android Only - Updates user's device firebase push notification token\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service has started successfully\n */\nexport const onNewToken = (fcmPushNotificationToken: string) => {\n return isValidPlatform(\n () =>\n errorHandler(() => OkHiNativeModule.onNewToken(fcmPushNotificationToken)),\n 'android'\n );\n};\n\n/**\n * Android Only - Should be invoked only when push notification is received.\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service has started successfully\n */\nexport const onMessageReceived = () => {\n return isValidPlatform(\n () => errorHandler(OkHiNativeModule.onMessageReceived),\n 'android'\n );\n};\n"],"mappings":"AAAA,SAASA,QAAT,QAAyB,cAAzB;AACA,SACEC,qCADF,EAEEC,6BAFF,EAGEC,yBAHF,EAIEC,mCAJF,EAKEC,+BALF,EAMEC,6BANF,EAOEC,yBAPF,EAQEC,2BARF,QASO,mBATP;AAUA,SAASC,YAAT,EAAuBC,eAAvB,QAA8C,oBAA9C;AACA,SAASC,gBAAT,QAAiC,qBAAjC;AAGA,SAASC,aAAT,QAA8B,yBAA9B;AACA,cAAc,SAAd;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,KAAK,GAAG,CACnBC,WADmB,EAEnBC,UAFmB,EAGnBC,GAHmB,EAInBC,GAJmB,EAKnBC,aALmB,EAMnBC,wBANmB,KAOhB;EACH,OAAOT,eAAe,CAAC,MAAM;IAC3B,IAAIV,QAAQ,CAACoB,EAAT,KAAgB,SAApB,EAA+B;MAC7B,OAAOT,gBAAgB,CAACU,wBAAjB,CACLP,WADK,EAELC,UAFK,EAGLC,GAHK,EAILC,GAJK,EAKLC,aALK,EAMLC,wBANK,CAAP;IAQD,CATD,MASO;MACL,OAAOR,gBAAgB,CAACU,wBAAjB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,EAAE;QAFO,CAAlB,CADI,CAAN;QAMA;MACD;IACF;;IACD,IAAI,EAAE,MAAM/B,yBAAyB,EAAjC,CAAJ,EAA0C;MACxCuB,MAAM,CACJ,IAAId,aAAJ,CAAkB;QAChBoB,IAAI,EAAEpB,aAAa,CAAC4C,kCADJ;QAEhBtB,OAAO,EAAE;MAFO,CAAlB,CADI,CAAN;MAMA;IACD;;IACD,IAAI,EAAE,MAAMjC,qCAAqC,EAA7C,CAAJ,EAAsD;MACpDyB,MAAM,CACJ,IAAId,aAAJ,CAAkB;QAChBoB,IAAI,EAAEpB,aAAa,CAAC6C,sBADJ;QAEhBvB,OAAO,EAAE;MAFO,CAAlB,CADI,CAAN;MAMA;IACD;;IACDT,OAAO,CAAC,IAAD,CAAP;EACD,CAhCM,CAAP;AAiCD,CAlCM;AAoCP;AACA;AACA;AACA;;AACA,OAAO,MAAMiC,UAAU,GAAIvC,wBAAD,IAAsC;EAC9D,OAAOT,eAAe,CACpB,MACED,YAAY,CAAC,MAAME,gBAAgB,CAAC+C,UAAjB,CAA4BvC,wBAA5B,CAAP,CAFM,EAGpB,SAHoB,CAAtB;AAKD,CANM;AAQP;AACA;AACA;AACA;;AACA,OAAO,MAAMwC,iBAAiB,GAAG,MAAM;EACrC,OAAOjD,eAAe,CACpB,MAAMD,YAAY,CAACE,gBAAgB,CAACgD,iBAAlB,CADE,EAEpB,SAFoB,CAAtB;AAID,CALM"}
1
+ {"version":3,"names":["Platform","isBackgroundLocationPermissionGranted","isGooglePlayServicesAvailable","isLocationServicesEnabled","requestBackgroundLocationPermission","requestEnableGooglePlayServices","requestEnableLocationServices","requestLocationPermission","isLocationPermissionGranted","errorHandler","isValidPlatform","OkHiNativeModule","OkHiException","start","phoneNumber","locationId","lat","lon","configuration","fcmPushNotificationToken","OS","startAddressVerification","startVerification","response","Promise","resolve","reject","location","user","id","result","phone","code","BAD_REQUEST_CODE","message","stopVerification","stopAddressVerification","startForegroundService","stopForegroundService","isForegroundServiceRunning","canStartVerification","requestServices","locationServicesStatus","googlePlayServices","backgroundLocationPerm","whenInUseLocationPerm","SERVICE_UNAVAILABLE_CODE","iosPerm","locationServicesRequestStatus","gPlayServices","androidPerm","UNSUPPORTED_PLATFORM_CODE","UNSUPPORTED_PLATFORM_MESSAGE","checkVerificationStartRequirements","isPlayServicesAvailable","PLAY_SERVICES_UNAVAILABLE_CODE","LOCATION_SERVICES_UNAVAILABLE_CODE","PERMISSION_DENIED_CODE","onNewToken","onMessageReceived"],"sources":["index.ts"],"sourcesContent":["import { Platform } from 'react-native';\nimport {\n isBackgroundLocationPermissionGranted,\n isGooglePlayServicesAvailable,\n isLocationServicesEnabled,\n requestBackgroundLocationPermission,\n requestEnableGooglePlayServices,\n requestEnableLocationServices,\n requestLocationPermission,\n isLocationPermissionGranted,\n} from '../OkCore/Helpers';\nimport { errorHandler, isValidPlatform } from '../OkCore/_helpers';\nimport { OkHiNativeModule } from '../OkHiNativeModule';\nimport type { OkVerifyStartConfiguration } from './types';\nimport type { OkCollectSuccessResponse } from '../OkCollect/types';\nimport { OkHiException } from '../OkCore/OkHiException';\nexport * from './types';\n/**\n * Starts verification for a particular address\n * @param {string} phoneNumber A users phone number\n * @param {string} locationId An OkHi location identifier obtained after successfull creation of addresses.\n * @param {number} lat The latitude of the created address\n * @param {number} lon The longitude of the created address\n * @param {Object} configuration Configures how verification will start on different platforms\n * @param {Object} configuration.android Specifices how verification will start on Android platforms\n * @param {boolean} configuration.android.withForeground Specifices if the foreground service will be turned on to speed up rate of verification, default is true\n * @param {string} fcmPushNotificationToken User's firebase push notification token\n * @returns {Promise<string>} A promise that resolves to a string value of the location identifier\n */\nexport const start = (\n phoneNumber: string,\n locationId: string,\n lat: number,\n lon: number,\n configuration?: OkVerifyStartConfiguration,\n fcmPushNotificationToken?: string\n) => {\n return isValidPlatform(() => {\n if (Platform.OS === 'android') {\n return OkHiNativeModule.startAddressVerification(\n phoneNumber,\n locationId,\n lat,\n lon,\n configuration,\n fcmPushNotificationToken\n );\n } else {\n return OkHiNativeModule.startAddressVerification(\n phoneNumber,\n locationId,\n lat,\n lon\n );\n }\n });\n};\n\n/**\n * Starts verification for a particular address using the response object returned by OkCollect\n * @param {Object} response Response returned by OkCollect\n * @param {Object} configuration Configures how verification will start on different platforms\n * @param {Object} configuration.android Specifices how verification will start on Android platforms\n * @param {boolean} configuration.android.withForeground Specifices if the foreground service will be turned on to speed up rate of verification\n * @returns {Promise<string>} A promise that resolves to a string value of the location identifier\n */\nexport const startVerification = async (\n response: OkCollectSuccessResponse,\n configuration?: OkVerifyStartConfiguration\n) => {\n return new Promise((resolve, reject) => {\n const { location, user } = response;\n if (location.id) {\n if (Platform.OS === 'android') {\n const result = OkHiNativeModule.startAddressVerification(\n user.phone,\n location.id,\n location.lat,\n location.lon,\n configuration,\n user.fcmPushNotificationToken\n );\n resolve(result);\n } else {\n const result = OkHiNativeModule.startAddressVerification(\n user.phone,\n location.id,\n location.lat,\n location.lon\n );\n resolve(result);\n }\n } else {\n reject(\n new OkHiException({\n code: OkHiException.BAD_REQUEST_CODE,\n message: 'Missing location id from response',\n })\n );\n }\n });\n};\n\n/**\n * Stops verification for a particular address using a user's phonenumber and OkHi location identifier\n * @param {string} phoneNumber The user's phone number\n * @param {string} locationId An OkHi location identifier obtained after successfull creation of addresses.\n * @returns {Promise<string>} A promise that resolves to a string value of the location identifier\n */\nexport const stopVerification = (phoneNumber: string, locationId: string) => {\n return isValidPlatform(() =>\n OkHiNativeModule.stopAddressVerification(phoneNumber, locationId)\n );\n};\n\n/**\n * Android Only - Starts a foreground service that speeds up rate of verification\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service has started successfully\n */\nexport const startForegroundService = () => {\n return isValidPlatform(\n () => errorHandler(OkHiNativeModule.startForegroundService),\n 'android'\n );\n};\n\n/**\n * Android Only - Stops previously started foreground services\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service has stopped successfully\n */\nexport const stopForegroundService = () => {\n return isValidPlatform(OkHiNativeModule.stopForegroundService, 'android');\n};\n\n/**\n * Android Only - Checks if the foreground service is running\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service is running\n */\nexport const isForegroundServiceRunning = () => {\n return isValidPlatform(\n OkHiNativeModule.isForegroundServiceRunning,\n 'android'\n );\n};\n\n/**\n * Checks whether all necessary permissions and services are available in order to start the address verification process\n * @param {Object} configuration Object that determines whether or not to request these permissions and services from the user\n * @param {boolean} configuration.requestServices Flag that determines whether to request the services from the user\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether or not all conditions are met to start the address verification process\n */\nexport const canStartVerification = (configuration?: {\n requestServices?: boolean;\n}): Promise<boolean> => {\n return new Promise(async (resolve, reject) => {\n const requestServices = configuration && configuration.requestServices;\n const locationServicesStatus = await isLocationServicesEnabled();\n const googlePlayServices =\n Platform.OS === 'android' ? await isGooglePlayServicesAvailable() : true;\n const backgroundLocationPerm =\n await isBackgroundLocationPermissionGranted();\n const whenInUseLocationPerm = await isLocationPermissionGranted();\n if (!requestServices) {\n resolve(\n locationServicesStatus && googlePlayServices && backgroundLocationPerm\n );\n return;\n }\n if (Platform.OS === 'ios') {\n if (!locationServicesStatus) {\n reject(\n new OkHiException({\n code: OkHiException.SERVICE_UNAVAILABLE_CODE,\n message: 'Location services is unavailable',\n })\n );\n return;\n }\n if (backgroundLocationPerm) {\n resolve(true);\n return;\n }\n if (whenInUseLocationPerm && !backgroundLocationPerm) {\n resolve(false);\n return;\n }\n const iosPerm = await requestBackgroundLocationPermission();\n resolve(iosPerm);\n return;\n } else if (Platform.OS === 'android') {\n const locationServicesRequestStatus =\n (await requestEnableLocationServices()) as boolean;\n const gPlayServices = await requestEnableGooglePlayServices();\n const androidPerm =\n (await requestLocationPermission()) &&\n (await requestBackgroundLocationPermission());\n resolve(locationServicesRequestStatus && gPlayServices && androidPerm);\n } else {\n reject(\n new OkHiException({\n code: OkHiException.UNSUPPORTED_PLATFORM_CODE,\n message: OkHiException.UNSUPPORTED_PLATFORM_MESSAGE,\n })\n );\n }\n });\n};\n\n/**\n * Checks whether all necessary permissions and services are available in order to start the address verification process\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether or not all conditions are met to start the address verification process\n */\nexport const checkVerificationStartRequirements = (): Promise<boolean> => {\n return new Promise(async (resolve, reject) => {\n if (Platform.OS === 'android') {\n const isPlayServicesAvailable = await isGooglePlayServicesAvailable();\n if (!isPlayServicesAvailable) {\n reject(\n new OkHiException({\n code: OkHiException.PLAY_SERVICES_UNAVAILABLE_CODE,\n message: 'Google Play Services is unavailable',\n })\n );\n return;\n }\n }\n if (!(await isLocationServicesEnabled())) {\n reject(\n new OkHiException({\n code: OkHiException.LOCATION_SERVICES_UNAVAILABLE_CODE,\n message: 'Location services unavailable',\n })\n );\n return;\n }\n if (!(await isBackgroundLocationPermissionGranted())) {\n reject(\n new OkHiException({\n code: OkHiException.PERMISSION_DENIED_CODE,\n message: 'Background Location permission not granted',\n })\n );\n return;\n }\n resolve(true);\n });\n};\n\n/**\n * Android Only - Updates user's device firebase push notification token\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service has started successfully\n */\nexport const onNewToken = (fcmPushNotificationToken: string) => {\n if (Platform.OS === 'android') {\n return OkHiNativeModule.onNewToken(fcmPushNotificationToken);\n }\n return Promise.resolve(true);\n};\n\n/**\n * Android Only - Should be invoked only when push notification is received.\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service has started successfully\n */\nexport const onMessageReceived = () => {\n if (Platform.OS === 'android') {\n return OkHiNativeModule.onMessageReceived();\n }\n return Promise.resolve(true);\n};\n"],"mappings":"AAAA,SAASA,QAAT,QAAyB,cAAzB;AACA,SACEC,qCADF,EAEEC,6BAFF,EAGEC,yBAHF,EAIEC,mCAJF,EAKEC,+BALF,EAMEC,6BANF,EAOEC,yBAPF,EAQEC,2BARF,QASO,mBATP;AAUA,SAASC,YAAT,EAAuBC,eAAvB,QAA8C,oBAA9C;AACA,SAASC,gBAAT,QAA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CAAgB,IAAhB,CAAP;AACD,CALM;AAOP;AACA;AACA;AACA;;AACA,OAAO,MAAMkC,iBAAiB,GAAG,MAAM;EACrC,IAAI3D,QAAQ,CAACoB,EAAT,KAAgB,SAApB,EAA+B;IAC7B,OAAOT,gBAAgB,CAACgD,iBAAjB,EAAP;EACD;;EACD,OAAOnC,OAAO,CAACC,OAAR,CAAgB,IAAhB,CAAP;AACD,CALM"}
@@ -32,6 +32,12 @@ declare type OkHiNativeModuleType = {
32
32
  onMessageReceived(): Promise<boolean>;
33
33
  isNotificationPermissionGranted(): Promise<boolean>;
34
34
  requestNotificationPermission(): Promise<boolean>;
35
+ fetchCurrentLocation(): Promise<null | {
36
+ lat: number;
37
+ lng: number;
38
+ accuracy: number;
39
+ }>;
40
+ fetchIOSLocationPermissionStatus(): Promise<'notDetermined' | 'restricted' | 'denied' | 'authorizedAlways' | 'authorizedWhenInUse' | 'authorized' | 'unknown'>;
35
41
  };
36
42
  export declare const OkHiNativeModule: OkHiNativeModuleType;
37
43
  export declare const OkHiNativeEvents: NativeEventEmitter;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-okhi",
3
- "version": "1.1.2",
3
+ "version": "1.1.3-beta.2",
4
4
  "description": "The OkHi React Native library enables you to collect and verify addresses from your users",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -17,7 +17,7 @@ Pod::Spec.new do |s|
17
17
  s.source_files = "ios/**/*.{h,m,mm,swift}"
18
18
 
19
19
  s.dependency "React-Core"
20
- s.dependency "OkHi", "1.9.3"
20
+ s.dependency "OkHi", "1.9.9"
21
21
 
22
22
  # Don't install the dependencies when we run `pod install` in the old architecture.
23
23
  if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
@@ -3,6 +3,7 @@ import {
3
3
  canOpenProtectedAppsSettings,
4
4
  isBackgroundLocationPermissionGranted,
5
5
  isLocationPermissionGranted,
6
+ OkHiException,
6
7
  OkHiLocation,
7
8
  } from '../OkCore';
8
9
  import { OkHiMode } from '../OkCore';
@@ -15,6 +16,15 @@ import type { AuthApplicationConfig } from '../OkCore/_types';
15
16
  import { Platform } from 'react-native';
16
17
  import { OkHiNativeModule } from '../OkHiNativeModule';
17
18
 
19
+ 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
+
18
28
  /**
19
29
  * @ignore
20
30
  */
@@ -58,48 +68,7 @@ export const generateStartDataPayload = async (
58
68
  name: 'react-native',
59
69
  },
60
70
  };
61
-
62
- let hasLocationPermission: boolean | undefined;
63
- try {
64
- hasLocationPermission = await isLocationPermissionGranted();
65
- } catch (error) {
66
- console.log(error);
67
- }
68
-
69
- let hasBackgroundLocationPermission: boolean | undefined;
70
- try {
71
- hasBackgroundLocationPermission =
72
- await isBackgroundLocationPermissionGranted();
73
- } catch (error) {
74
- console.log(error);
75
- }
76
-
77
- if (
78
- typeof hasLocationPermission === 'boolean' &&
79
- typeof hasBackgroundLocationPermission === 'boolean'
80
- ) {
81
- payload.context.permissions = {
82
- location: hasBackgroundLocationPermission
83
- ? 'always'
84
- : hasLocationPermission
85
- ? 'whenInUse'
86
- : 'denied',
87
- };
88
- }
89
-
90
- if (Platform.OS === 'android') {
91
- const { manufacturer, model } = await OkHiNativeModule.retrieveDeviceInfo();
92
- payload.context.device = {
93
- manufacturer,
94
- model,
95
- };
96
- payload.context.permissions = {
97
- ...payload.context.permissions,
98
- };
99
- }
100
71
  payload.config = {
101
- protectedApps:
102
- Platform.OS === 'android' && (await canOpenProtectedAppsSettings()),
103
72
  streetView:
104
73
  typeof props.config?.streetView === 'boolean'
105
74
  ? props.config.streetView
@@ -118,7 +87,77 @@ export const generateStartDataPayload = async (
118
87
  ? props.config?.addressTypes?.work
119
88
  : true,
120
89
  },
90
+ protectedApps:
91
+ Platform.OS === 'android' && (await canOpenProtectedAppsSettings()),
121
92
  };
93
+
94
+ if (Platform.OS === 'ios') {
95
+ const status = await OkHiNativeModule.fetchIOSLocationPermissionStatus();
96
+ if (status !== 'notDetermined') {
97
+ payload.context.permissions = {
98
+ location:
99
+ status === 'authorizedWhenInUse'
100
+ ? 'whenInUse'
101
+ : status === 'authorizedAlways' || status === 'authorized'
102
+ ? 'always'
103
+ : 'denided',
104
+ };
105
+ if (
106
+ status === 'authorized' ||
107
+ status === 'authorizedWhenInUse' ||
108
+ status === 'authorizedAlways'
109
+ ) {
110
+ const location = await fetchCurrentLocation();
111
+ if (location) {
112
+ payload.context.coordinates = {
113
+ currentLocation: {
114
+ lat: location.lat,
115
+ lng: location.lng,
116
+ accuracy: location.accuracy,
117
+ },
118
+ };
119
+ }
120
+ }
121
+ }
122
+ } else if (Platform.OS === 'android') {
123
+ let hasLocationPermission: boolean | undefined;
124
+ try {
125
+ hasLocationPermission = await isLocationPermissionGranted();
126
+ } catch (error) {
127
+ console.log(error);
128
+ }
129
+
130
+ let hasBackgroundLocationPermission: boolean | undefined;
131
+ try {
132
+ hasBackgroundLocationPermission =
133
+ await isBackgroundLocationPermissionGranted();
134
+ } catch (error) {
135
+ console.log(error);
136
+ }
137
+
138
+ if (
139
+ typeof hasLocationPermission === 'boolean' &&
140
+ typeof hasBackgroundLocationPermission === 'boolean'
141
+ ) {
142
+ payload.context.permissions = {
143
+ location: hasBackgroundLocationPermission
144
+ ? 'always'
145
+ : hasLocationPermission
146
+ ? 'whenInUse'
147
+ : 'denied',
148
+ };
149
+ }
150
+ const { manufacturer, model } = await OkHiNativeModule.retrieveDeviceInfo();
151
+ payload.context.device = {
152
+ manufacturer,
153
+ model,
154
+ };
155
+ } else {
156
+ throw new OkHiException({
157
+ code: OkHiException.UNSUPPORTED_PLATFORM_CODE,
158
+ message: OkHiException.UNAUTHORIZED_MESSAGE,
159
+ });
160
+ }
122
161
  return payload;
123
162
  };
124
163
 
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "okhiWebReactNative",
3
- "version": "1.1.2"
3
+ "version": "1.1.3-beta.1"
4
4
  }
@@ -4,6 +4,7 @@ import { OkHiException } from './OkHiException';
4
4
  import type { AuthApplicationConfig, OkHiAccessScope } from './_types';
5
5
  import { getApplicationConfiguration } from './';
6
6
  import { OkHiNativeModule } from '../OkHiNativeModule';
7
+ import { Platform } from 'react-native';
7
8
 
8
9
  /**
9
10
  * @ignore
@@ -71,10 +72,12 @@ export class OkHiAuth {
71
72
  const { data } = await axios.post(url, payload, {
72
73
  headers,
73
74
  });
74
- await OkHiNativeModule.setItem(
75
- 'okhi:recent:token',
76
- data.authorization_token
77
- ); //TODO: move all anonymousSignIn to native code
75
+ if (Platform.OS === 'android') {
76
+ await OkHiNativeModule.setItem(
77
+ 'okhi:recent:token',
78
+ data.authorization_token
79
+ ); //TODO: move all anonymousSignIn to native code
80
+ }
78
81
  resolve(data.authorization_token);
79
82
  }
80
83
  } catch (error) {
@@ -50,6 +50,20 @@ type OkHiNativeModuleType = {
50
50
  onMessageReceived(): Promise<boolean>;
51
51
  isNotificationPermissionGranted(): Promise<boolean>;
52
52
  requestNotificationPermission(): Promise<boolean>;
53
+ fetchCurrentLocation(): Promise<null | {
54
+ lat: number;
55
+ lng: number;
56
+ accuracy: number;
57
+ }>;
58
+ fetchIOSLocationPermissionStatus(): Promise<
59
+ | 'notDetermined'
60
+ | 'restricted'
61
+ | 'denied'
62
+ | 'authorizedAlways'
63
+ | 'authorizedWhenInUse'
64
+ | 'authorized'
65
+ | 'unknown'
66
+ >;
53
67
  };
54
68
 
55
69
  export const OkHiNativeModule: OkHiNativeModuleType = NativeModules.Okhi
@@ -251,11 +251,10 @@ export const checkVerificationStartRequirements = (): Promise<boolean> => {
251
251
  * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service has started successfully
252
252
  */
253
253
  export const onNewToken = (fcmPushNotificationToken: string) => {
254
- return isValidPlatform(
255
- () =>
256
- errorHandler(() => OkHiNativeModule.onNewToken(fcmPushNotificationToken)),
257
- 'android'
258
- );
254
+ if (Platform.OS === 'android') {
255
+ return OkHiNativeModule.onNewToken(fcmPushNotificationToken);
256
+ }
257
+ return Promise.resolve(true);
259
258
  };
260
259
 
261
260
  /**
@@ -263,8 +262,8 @@ export const onNewToken = (fcmPushNotificationToken: string) => {
263
262
  * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service has started successfully
264
263
  */
265
264
  export const onMessageReceived = () => {
266
- return isValidPlatform(
267
- () => errorHandler(OkHiNativeModule.onMessageReceived),
268
- 'android'
269
- );
265
+ if (Platform.OS === 'android') {
266
+ return OkHiNativeModule.onMessageReceived();
267
+ }
268
+ return Promise.resolve(true);
270
269
  };