react-native-okhi 1.1.1-beta.2 → 1.1.1-beta.4

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.
@@ -35,6 +35,7 @@ import io.okhi.android_core.models.OkPreference;
35
35
  import io.okhi.android_okverify.OkVerify;
36
36
  import io.okhi.android_okverify.interfaces.OkVerifyCallback;
37
37
  import io.okhi.android_okverify.models.OkHiNotification;
38
+ import io.okhi.android_okverify.models.OkVerifyPushNotificationService;
38
39
 
39
40
  @ReactModule(name = OkhiModule.NAME)
40
41
  public class OkhiModule extends ReactContextBaseJavaModule {
@@ -182,12 +183,12 @@ public class OkhiModule extends ReactContextBaseJavaModule {
182
183
  }
183
184
 
184
185
  @ReactMethod
185
- public void startAddressVerification(String phoneNumber, String locationId, Float lat, Float lon, ReadableMap config, Promise promise) {
186
+ public void startAddressVerification(String phoneNumber, String locationId, Float lat, Float lon, ReadableMap config, String fcmPushNotificationToken, Promise promise) {
186
187
  if (okVerify == null) {
187
188
  promise.reject("unauthorized", "failed to initialise okhi");
188
189
  return;
189
190
  }
190
- OkHiUser user = new OkHiUser.Builder(phoneNumber).build();
191
+ OkHiUser user = new OkHiUser.Builder(phoneNumber).withFcmPushNotificationToken(fcmPushNotificationToken).build();
191
192
  OkHiLocation location = new OkHiLocation.Builder(locationId, lat, lon).build();
192
193
  Boolean withForeground = true;
193
194
  Dynamic foregroundConfig = getConfig(config, "withForeground");
@@ -314,4 +315,15 @@ public class OkhiModule extends ReactContextBaseJavaModule {
314
315
  }
315
316
  }
316
317
 
318
+ @ReactMethod
319
+ public void onNewToken(String fcmPushNotificationToken, Promise promise) {
320
+ OkVerifyPushNotificationService.onNewToken(fcmPushNotificationToken, getReactApplicationContext());
321
+ promise.resolve(true);
322
+ }
323
+
324
+ @ReactMethod
325
+ public void onMessageReceived(Promise promise) {
326
+ OkVerifyPushNotificationService.onMessageReceived(getReactApplicationContext());
327
+ promise.resolve(true);
328
+ }
317
329
  }
@@ -108,7 +108,10 @@ const OkHiLocationManager = props => {
108
108
  } else if (response.message === 'request_enable_protected_apps') {
109
109
  (0, _OkCore.openProtectedAppsSettings)();
110
110
  } else {
111
- onSuccess({ ...response.payload,
111
+ onSuccess({
112
+ user: { ...response.payload.user,
113
+ fcmPushNotificationToken: user.fcmPushNotificationToken
114
+ },
112
115
  location: (0, _Util.parseOkHiLocation)(response.payload.location),
113
116
  startVerification: function (config) {
114
117
  const createdUser = { ...this.user
@@ -122,7 +125,7 @@ const OkHiLocationManager = props => {
122
125
  message: 'Missing location id from response'
123
126
  }));
124
127
  } else {
125
- (0, _OkVerify.start)(createdUser.phone, location.id, location.lat, location.lon, config).then(resolve).catch(reject);
128
+ (0, _OkVerify.start)(createdUser.phone, location.id, location.lat, location.lon, config, createdUser.fcmPushNotificationToken).then(resolve).catch(reject);
126
129
  }
127
130
  });
128
131
  }
@@ -1 +1 @@
1
- {"version":3,"names":["OkHiLocationManager","props","token","setToken","useState","applicationConfiguration","setApplicationConfiguration","startPayload","setStartPaylaod","defaultStyle","flex","style","user","onSuccess","onCloseRequest","onError","loader","launch","webViewRef","useRef","useEffect","phone","getApplicationConfiguration","then","config","OkHiException","code","UNAUTHORIZED_CODE","message","UNAUTHORIZED_MESSAGE","auth","OkHiAuth","anonymousSignInWithPhoneNumber","catch","error","generateStartDataPayload","Platform","OS","Version","OkHiNativeModule","setItem","JSON","stringify","payload","url","getFrameUrl","console","handleOnMessage","nativeEvent","data","response","parse","UNKNOWN_ERROR_CODE","toString","openProtectedAppsSettings","location","parseOkHiLocation","startVerification","createdUser","Promise","resolve","reject","id","BAD_REQUEST_CODE","sv","lat","lon","errorMessage","Error","handleOnError","NETWORK_ERROR_CODE","NETWORK_ERROR_MESSAGE","handleModalRequestClose","current","goBack","renderContent","jsAfterLoad","jsBeforeLoad","generateJavaScriptStartScript","uri","undefined"],"sources":["OkHiLocationManager.tsx"],"sourcesContent":["import React, { useState, useEffect, useRef } from 'react';\nimport { Modal, SafeAreaView, Platform } from 'react-native';\nimport { WebView, WebViewMessageEvent } from 'react-native-webview';\nimport { Spinner } from './Spinner';\nimport type {\n OkHiLocationManagerResponse,\n OkHiLocationManagerProps,\n OkHiLocationManagerStartDataPayload,\n} from './types';\nimport {\n getFrameUrl,\n generateJavaScriptStartScript,\n generateStartDataPayload,\n parseOkHiLocation,\n} from './Util';\nimport { OkHiException } from '../OkCore/OkHiException';\nimport { OkHiAuth } from '../OkCore/OkHiAuth';\nimport type { AuthApplicationConfig } from '../OkCore/_types';\nimport { start as sv } from '../OkVerify';\nimport type { OkVerifyStartConfiguration } from '../OkVerify/types';\nimport {\n getApplicationConfiguration,\n openProtectedAppsSettings,\n} from '../OkCore';\nimport { OkHiNativeModule } from '../OkHiNativeModule';\n\n/**\n * The OkHiLocationManager React Component is used to display an in app modal, enabling the user to quickly create an accurate OkHi address.\n */\nexport const OkHiLocationManager = (props: OkHiLocationManagerProps) => {\n const [token, setToken] = useState<string | null>(null);\n const [applicationConfiguration, setApplicationConfiguration] =\n useState<AuthApplicationConfig | null>(null);\n const [startPayload, setStartPaylaod] =\n useState<null | OkHiLocationManagerStartDataPayload>(null);\n const defaultStyle = { flex: 1 };\n const style = props.style\n ? { ...props.style, ...defaultStyle }\n : defaultStyle;\n\n const { user, onSuccess, onCloseRequest, onError, loader, launch } = props;\n const webViewRef = useRef<WebView | null>(null);\n\n useEffect(() => {\n if (applicationConfiguration == null && token == null && user.phone) {\n getApplicationConfiguration()\n .then((config) => {\n if (!config && launch) {\n onError(\n new OkHiException({\n code: OkHiException.UNAUTHORIZED_CODE,\n message: OkHiException.UNAUTHORIZED_MESSAGE,\n })\n );\n } else if (config) {\n setApplicationConfiguration(config);\n const auth = new OkHiAuth();\n auth\n .anonymousSignInWithPhoneNumber(user.phone, ['verify'], config)\n .then(setToken)\n .catch(onError);\n }\n })\n .catch((error) => {\n if (launch) {\n onError(error);\n }\n });\n }\n }, [onError, user.phone, launch, applicationConfiguration, token]);\n\n useEffect(() => {\n if (token !== null && applicationConfiguration !== null) {\n // TODO: handle faliure\n generateStartDataPayload(props, token, applicationConfiguration)\n .then((startPayload) => {\n setStartPaylaod(startPayload);\n if (Platform.OS === 'android' && Platform.Version > 25) {\n OkHiNativeModule.setItem(\n 'okcollect-launch-payload',\n JSON.stringify({\n message: 'select_location',\n payload: startPayload,\n url: getFrameUrl(applicationConfiguration),\n })\n ).catch(console.error);\n }\n })\n .catch(console.error);\n }\n }, [applicationConfiguration, props, token]);\n\n const handleOnMessage = ({ nativeEvent: { data } }: WebViewMessageEvent) => {\n try {\n const response: OkHiLocationManagerResponse = JSON.parse(data);\n if (response.message === 'fatal_exit') {\n onError(\n new OkHiException({\n code: OkHiException.UNKNOWN_ERROR_CODE,\n message: response.payload.toString(),\n })\n );\n } else if (response.message === 'exit_app') {\n onCloseRequest();\n } else if (response.message === 'request_enable_protected_apps') {\n openProtectedAppsSettings();\n } else {\n onSuccess({\n ...response.payload,\n location: parseOkHiLocation(response.payload.location),\n startVerification: function (config?: OkVerifyStartConfiguration) {\n const createdUser = { ...this.user };\n const location = { ...this.location };\n return new Promise((resolve, reject) => {\n if (!location.id) {\n reject(\n new OkHiException({\n code: OkHiException.BAD_REQUEST_CODE,\n message: 'Missing location id from response',\n })\n );\n } else {\n sv(\n createdUser.phone,\n location.id,\n location.lat,\n location.lon,\n config\n )\n .then(resolve)\n .catch(reject);\n }\n });\n },\n });\n }\n } catch (error) {\n let errorMessage = 'Something went wrong';\n if (error instanceof Error) {\n errorMessage = error.message;\n }\n onError(\n new OkHiException({\n code: OkHiException.UNKNOWN_ERROR_CODE,\n message: errorMessage,\n })\n );\n }\n };\n\n const handleOnError = () => {\n onError(\n new OkHiException({\n code: OkHiException.NETWORK_ERROR_CODE,\n message: OkHiException.NETWORK_ERROR_MESSAGE,\n })\n );\n };\n\n const handleModalRequestClose = () => {\n webViewRef.current?.goBack();\n };\n\n const renderContent = () => {\n if (token === null || applicationConfiguration == null) {\n return loader || <Spinner />;\n }\n\n if (startPayload === null) {\n return loader || <Spinner />;\n }\n\n const { jsAfterLoad, jsBeforeLoad } = generateJavaScriptStartScript({\n message: 'select_location',\n payload: startPayload,\n });\n\n return (\n <SafeAreaView style={style}>\n <WebView\n source={{ uri: getFrameUrl(applicationConfiguration) }}\n injectedJavaScriptBeforeContentLoaded={\n Platform.OS === 'ios' ? jsBeforeLoad : undefined\n }\n injectedJavaScript={Platform.OS === 'ios' ? undefined : jsAfterLoad}\n onMessage={handleOnMessage}\n onError={handleOnError}\n onHttpError={handleOnError}\n geolocationEnabled={true}\n allowsBackForwardNavigationGestures={true}\n ref={webViewRef}\n />\n </SafeAreaView>\n );\n };\n\n return (\n <Modal\n animationType=\"slide\"\n transparent={false}\n visible={launch}\n onRequestClose={handleModalRequestClose}\n >\n {launch ? renderContent() : null}\n </Modal>\n );\n};\n\nexport default OkHiLocationManager;\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AAMA;;AAMA;;AACA;;AAEA;;AAEA;;AAIA;;;;;;AAEA;AACA;AACA;AACO,MAAMA,mBAAmB,GAAIC,KAAD,IAAqC;EACtE,MAAM,CAACC,KAAD,EAAQC,QAAR,IAAoB,IAAAC,eAAA,EAAwB,IAAxB,CAA1B;EACA,MAAM,CAACC,wBAAD,EAA2BC,2BAA3B,IACJ,IAAAF,eAAA,EAAuC,IAAvC,CADF;EAEA,MAAM,CAACG,YAAD,EAAeC,eAAf,IACJ,IAAAJ,eAAA,EAAqD,IAArD,CADF;EAEA,MAAMK,YAAY,GAAG;IAAEC,IAAI,EAAE;EAAR,CAArB;EACA,MAAMC,KAAK,GAAGV,KAAK,CAACU,KAAN,GACV,EAAE,GAAGV,KAAK,CAACU,KAAX;IAAkB,GAAGF;EAArB,CADU,GAEVA,YAFJ;EAIA,MAAM;IAAEG,IAAF;IAAQC,SAAR;IAAmBC,cAAnB;IAAmCC,OAAnC;IAA4CC,MAA5C;IAAoDC;EAApD,IAA+DhB,KAArE;EACA,MAAMiB,UAAU,GAAG,IAA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IAAkBG,wBAAwB,IAAI,IAAlD,EAAwD;MACtD,OAAOW,MAAM,iBAAI,6BAAC,gBAAD,OAAjB;IACD;;IAED,IAAIT,YAAY,KAAK,IAArB,EAA2B;MACzB,OAAOS,MAAM,iBAAI,6BAAC,gBAAD,OAAjB;IACD;;IAED,MAAM;MAAE4D,WAAF;MAAeC;IAAf,IAAgC,IAAAC,mCAAA,EAA8B;MAClElD,OAAO,EAAE,iBADyD;MAElEe,OAAO,EAAEpC;IAFyD,CAA9B,CAAtC;IAKA,oBACE,6BAAC,yBAAD;MAAc,KAAK,EAAEI;IAArB,gBACE,6BAAC,2BAAD;MACE,MAAM,EAAE;QAAEoE,GAAG,EAAE,IAAAlC,iBAAA,EAAYxC,wBAAZ;MAAP,CADV;MAEE,qCAAqC,EACnC+B,qBAAA,CAASC,EAAT,KAAgB,KAAhB,GAAwBwC,YAAxB,GAAuCG,SAH3C;MAKE,kBAAkB,EAAE5C,qBAAA,CAASC,EAAT,KAAgB,KAAhB,GAAwB2C,SAAxB,GAAoCJ,WAL1D;MAME,SAAS,EAAE7B,eANb;MAOE,OAAO,EAAEsB,aAPX;MAQE,WAAW,EAAEA,aARf;MASE,kBAAkB,EAAE,IATtB;MAUE,mCAAmC,EAAE,IAVvC;MAWE,GAAG,EAAEnD;IAXP,EADF,CADF;EAiBD,CA/BD;;EAiCA,oBACE,6BAAC,kBAAD;IACE,aAAa,EAAC,OADhB;IAEE,WAAW,EAAE,KAFf;IAGE,OAAO,EAAED,MAHX;IAIE,cAAc,EAAEuD;EAJlB,GAMGvD,MAAM,GAAG0D,aAAa,EAAhB,GAAqB,IAN9B,CADF;AAUD,CAjLM;;;eAmLQ3E,mB"}
1
+ {"version":3,"names":["OkHiLocationManager","props","token","setToken","useState","applicationConfiguration","setApplicationConfiguration","startPayload","setStartPaylaod","defaultStyle","flex","style","user","onSuccess","onCloseRequest","onError","loader","launch","webViewRef","useRef","useEffect","phone","getApplicationConfiguration","then","config","OkHiException","code","UNAUTHORIZED_CODE","message","UNAUTHORIZED_MESSAGE","auth","OkHiAuth","anonymousSignInWithPhoneNumber","catch","error","generateStartDataPayload","Platform","OS","Version","OkHiNativeModule","setItem","JSON","stringify","payload","url","getFrameUrl","console","handleOnMessage","nativeEvent","data","response","parse","UNKNOWN_ERROR_CODE","toString","openProtectedAppsSettings","fcmPushNotificationToken","location","parseOkHiLocation","startVerification","createdUser","Promise","resolve","reject","id","BAD_REQUEST_CODE","sv","lat","lon","errorMessage","Error","handleOnError","NETWORK_ERROR_CODE","NETWORK_ERROR_MESSAGE","handleModalRequestClose","current","goBack","renderContent","jsAfterLoad","jsBeforeLoad","generateJavaScriptStartScript","uri","undefined"],"sources":["OkHiLocationManager.tsx"],"sourcesContent":["import React, { useState, useEffect, useRef } from 'react';\nimport { Modal, SafeAreaView, Platform } from 'react-native';\nimport { WebView, WebViewMessageEvent } from 'react-native-webview';\nimport { Spinner } from './Spinner';\nimport type {\n OkHiLocationManagerResponse,\n OkHiLocationManagerProps,\n OkHiLocationManagerStartDataPayload,\n} from './types';\nimport {\n getFrameUrl,\n generateJavaScriptStartScript,\n generateStartDataPayload,\n parseOkHiLocation,\n} from './Util';\nimport { OkHiException } from '../OkCore/OkHiException';\nimport { OkHiAuth } from '../OkCore/OkHiAuth';\nimport type { AuthApplicationConfig } from '../OkCore/_types';\nimport { start as sv } from '../OkVerify';\nimport type { OkVerifyStartConfiguration } from '../OkVerify/types';\nimport {\n getApplicationConfiguration,\n openProtectedAppsSettings,\n} from '../OkCore';\nimport { OkHiNativeModule } from '../OkHiNativeModule';\n\n/**\n * The OkHiLocationManager React Component is used to display an in app modal, enabling the user to quickly create an accurate OkHi address.\n */\nexport const OkHiLocationManager = (props: OkHiLocationManagerProps) => {\n const [token, setToken] = useState<string | null>(null);\n const [applicationConfiguration, setApplicationConfiguration] =\n useState<AuthApplicationConfig | null>(null);\n const [startPayload, setStartPaylaod] =\n useState<null | OkHiLocationManagerStartDataPayload>(null);\n const defaultStyle = { flex: 1 };\n const style = props.style\n ? { ...props.style, ...defaultStyle }\n : defaultStyle;\n\n const { user, onSuccess, onCloseRequest, onError, loader, launch } = props;\n const webViewRef = useRef<WebView | null>(null);\n\n useEffect(() => {\n if (applicationConfiguration == null && token == null && user.phone) {\n getApplicationConfiguration()\n .then((config) => {\n if (!config && launch) {\n onError(\n new OkHiException({\n code: OkHiException.UNAUTHORIZED_CODE,\n message: OkHiException.UNAUTHORIZED_MESSAGE,\n })\n );\n } else if (config) {\n setApplicationConfiguration(config);\n const auth = new OkHiAuth();\n auth\n .anonymousSignInWithPhoneNumber(user.phone, ['verify'], config)\n .then(setToken)\n .catch(onError);\n }\n })\n .catch((error) => {\n if (launch) {\n onError(error);\n }\n });\n }\n }, [onError, user.phone, launch, applicationConfiguration, token]);\n\n useEffect(() => {\n if (token !== null && applicationConfiguration !== null) {\n // TODO: handle faliure\n generateStartDataPayload(props, token, applicationConfiguration)\n .then((startPayload) => {\n setStartPaylaod(startPayload);\n if (Platform.OS === 'android' && Platform.Version > 25) {\n OkHiNativeModule.setItem(\n 'okcollect-launch-payload',\n JSON.stringify({\n message: 'select_location',\n payload: startPayload,\n url: getFrameUrl(applicationConfiguration),\n })\n ).catch(console.error);\n }\n })\n .catch(console.error);\n }\n }, [applicationConfiguration, props, token]);\n\n const handleOnMessage = ({ nativeEvent: { data } }: WebViewMessageEvent) => {\n try {\n const response: OkHiLocationManagerResponse = JSON.parse(data);\n if (response.message === 'fatal_exit') {\n onError(\n new OkHiException({\n code: OkHiException.UNKNOWN_ERROR_CODE,\n message: response.payload.toString(),\n })\n );\n } else if (response.message === 'exit_app') {\n onCloseRequest();\n } else if (response.message === 'request_enable_protected_apps') {\n openProtectedAppsSettings();\n } else {\n onSuccess({\n user: {\n ...response.payload.user,\n fcmPushNotificationToken: user.fcmPushNotificationToken,\n },\n location: parseOkHiLocation(response.payload.location),\n startVerification: function (config?: OkVerifyStartConfiguration) {\n const createdUser = { ...this.user };\n const location = { ...this.location };\n return new Promise((resolve, reject) => {\n if (!location.id) {\n reject(\n new OkHiException({\n code: OkHiException.BAD_REQUEST_CODE,\n message: 'Missing location id from response',\n })\n );\n } else {\n sv(\n createdUser.phone,\n location.id,\n location.lat,\n location.lon,\n config,\n createdUser.fcmPushNotificationToken\n )\n .then(resolve)\n .catch(reject);\n }\n });\n },\n });\n }\n } catch (error) {\n let errorMessage = 'Something went wrong';\n if (error instanceof Error) {\n errorMessage = error.message;\n }\n onError(\n new OkHiException({\n code: OkHiException.UNKNOWN_ERROR_CODE,\n message: errorMessage,\n })\n );\n }\n };\n\n const handleOnError = () => {\n onError(\n new OkHiException({\n code: OkHiException.NETWORK_ERROR_CODE,\n message: OkHiException.NETWORK_ERROR_MESSAGE,\n })\n );\n };\n\n const handleModalRequestClose = () => {\n webViewRef.current?.goBack();\n };\n\n const renderContent = () => {\n if (token === null || applicationConfiguration == null) {\n return loader || <Spinner />;\n }\n\n if (startPayload === null) {\n return loader || <Spinner />;\n }\n\n const { jsAfterLoad, jsBeforeLoad } = generateJavaScriptStartScript({\n message: 'select_location',\n payload: startPayload,\n });\n\n return (\n <SafeAreaView style={style}>\n <WebView\n source={{ uri: getFrameUrl(applicationConfiguration) }}\n injectedJavaScriptBeforeContentLoaded={\n Platform.OS === 'ios' ? jsBeforeLoad : undefined\n }\n injectedJavaScript={Platform.OS === 'ios' ? undefined : jsAfterLoad}\n onMessage={handleOnMessage}\n onError={handleOnError}\n onHttpError={handleOnError}\n geolocationEnabled={true}\n allowsBackForwardNavigationGestures={true}\n ref={webViewRef}\n />\n </SafeAreaView>\n );\n };\n\n return (\n <Modal\n animationType=\"slide\"\n transparent={false}\n visible={launch}\n onRequestClose={handleModalRequestClose}\n >\n {launch ? renderContent() : null}\n </Modal>\n );\n};\n\nexport default OkHiLocationManager;\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AAMA;;AAMA;;AACA;;AAEA;;AAEA;;AAIA;;;;;;AAEA;AACA;AACA;AACO,MAAMA,mBAAmB,GAAIC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uCG,SAH3C;MAKE,kBAAkB,EAAE7C,qBAAA,CAASC,EAAT,KAAgB,KAAhB,GAAwB4C,SAAxB,GAAoCJ,WAL1D;MAME,SAAS,EAAE9B,eANb;MAOE,OAAO,EAAEuB,aAPX;MAQE,WAAW,EAAEA,aARf;MASE,kBAAkB,EAAE,IATtB;MAUE,mCAAmC,EAAE,IAVvC;MAWE,GAAG,EAAEpD;IAXP,EADF,CADF;EAiBD,CA/BD;;EAiCA,oBACE,6BAAC,kBAAD;IACE,aAAa,EAAC,OADhB;IAEE,WAAW,EAAE,KAFf;IAGE,OAAO,EAAED,MAHX;IAIE,cAAc,EAAEwD;EAJlB,GAMGxD,MAAM,GAAG2D,aAAa,EAAhB,GAAqB,IAN9B,CADF;AAUD,CArLM;;;eAuLQ5E,mB"}
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "okhiWebReactNative",
3
- "version": "1.1.1-beta.1"
3
+ "version": "1.1.1-beta.4"
4
4
  }
@@ -13,6 +13,8 @@ var _OkHiException = require("./OkHiException");
13
13
 
14
14
  var _ = require("./");
15
15
 
16
+ var _OkHiNativeModule = require("../OkHiNativeModule");
17
+
16
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
19
 
18
20
  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; }
@@ -83,6 +85,8 @@ class OkHiAuth {
83
85
  } = await _axios.default.post(url, payload, {
84
86
  headers
85
87
  });
88
+ await _OkHiNativeModule.OkHiNativeModule.setItem('okhi:recent:token', data.authorization_token); //TODO: move all anonymousSignIn to native code
89
+
86
90
  resolve(data.authorization_token);
87
91
  }
88
92
  } catch (error) {
@@ -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","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 './';\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 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;;;;;;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,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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AAhB;UACA,MAAM;YAAEgB;UAAF,IAAW,MAAMC,cAAA,CAAMC,IAAN,CAAWX,GAAX,EAAgBb,OAAhB,EAAyB;YAC9CoB;UAD8C,CAAzB,CAAvB;UAGAlB,OAAO,CAACoB,IAAI,CAACG,mBAAN,CAAP;QACD;MACF,CAzBD,CAyBE,OAAOC,KAAP,EAAc;QACdvB,MAAM,CAAC,KAAKwB,iBAAL,CAAuBD,KAAvB,CAAD,CAAN;MACD;IACF,CA7BM,CAAP;EA8BD;;EAEOC,iBAAiB,CAACD,KAAD,EAAa;IACpC,IAAI,CAACA,KAAK,CAACE,QAAX,EAAqB;MACnB,OAAO,IAAIrB,4BAAJ,CAAkB;QACvBC,IAAI,EAAED,4BAAA,CAAcsB,kBADG;QAEvBnB,OAAO,EAAEH,4BAAA,CAAcuB;MAFA,CAAlB,CAAP;IAID;;IACD,QAAQJ,KAAK,CAACE,QAAN,CAAeG,MAAvB;MACE,KAAK,GAAL;QACE,OAAO,IAAIxB,4BAAJ,CAAkB;UACvBC,IAAI,EAAED,4BAAA,CAAcyB,kBADG;UAEvBtB,OAAO,EAAEH,4BAAA,CAAc0B;QAFA,CAAlB,CAAP;;MAIF,KAAK,GAAL;QACE,OAAO,IAAI1B,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,CAAc2B,kBADG;UAEvBxB,OAAO,EAAEgB,KAAK,CAAChB,OAAN,IAAiBH,4BAAA,CAAc4B;QAFjB,CAAlB,CAAP;IAZJ;EAiBD;;AA/FmB"}
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,0BARa;;IAAA,uCAUjB,uBAAsB,KAAKD,WAAY,EAAxC,GAA4C,KAAKC,0BAV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AFjB,CAAlB,CAAP;IAZJ;EAiBD;;AAnGmB"}
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["/**\n * Defines the structure of the user object requried by OkHi services and libraries.\n */\nexport interface OkHiUser {\n /**\n * The user's phone number. Must be MSISDN standard format. e.g +254712345678.\n */\n phone: string;\n /**\n * The user's first name.\n */\n firstName?: string;\n /**\n * The user's last name.\n */\n lastName?: string;\n /**\n * The user's email address.\n */\n email?: string;\n /**\n * The OkHi's userId. Usually obtained after a user successfully creates an OkHi address.\n */\n id?: string;\n}\n\n/**\n * Defines the current mode you'll be using OkHi's services as well as your application's meta information.\n */\nexport interface OkHiAppContext {\n /**\n * The current mode you'll be using OkHi services.\n */\n mode: 'sandbox' | 'prod' | string;\n /**\n * Your application's meta information.\n */\n app?: {\n /**\n * Your application's name.\n */\n name: string;\n /**\n * Your application's current version.\n */\n version: string;\n /**\n * Your application's current build number.\n */\n build: number;\n };\n /**\n * Meta information about the current developer.\n */\n developer?: string;\n}\n\n/**\n * Defines the structure of the OkHi location object once an address has been successfully created by the user.\n */\nexport interface OkHiLocation {\n /**\n * The latitude of the location.\n */\n lat: number;\n /**\n * The longitude of the location.\n */\n lon: number;\n /**\n * The OkHi's locationId. Usually obtained once an address has been successfully created by the user.\n */\n id?: string;\n /**\n * The id of a common residential or geological space such as apartment building or office block.\n */\n placeId?: string;\n /**\n * Geocode system for identifying an area anywhere on the Earth.\n * See https://plus.codes/\n */\n plusCode?: string;\n /**\n * The location's property name.\n */\n propertyName?: string;\n /**\n * The location's street name.\n */\n streetName?: string;\n /**\n * A string that can be used to render information about the location.\n */\n title?: string;\n /**\n * A string that can be used to render meta information about the location.\n */\n subtitle?: string;\n /**\n * User generated directions to the location.\n */\n directions?: string;\n /**\n * User generated meta information about the location, how to access it and any other relevant notes.\n */\n otherInformation?: string;\n /**\n * A link to the user's address visible on browser or desktop.\n */\n url?: string;\n /**\n * A Google's StreetView Panorama Id, if the address was created using Google StreetView.\n * See: https://developers.google.com/maps/documentation/javascript/streetview\n */\n streetViewPanoId?: string;\n /**\n * A Google's StreetView Panorama Url, if the address was created using Google StreetView.\n * See: https://developers.google.com/maps/documentation/javascript/streetview\n */\n streetViewPanoUrl?: string;\n /**\n * The OkHi's userId. Usually obtained after a user successfully creates an OkHi address.\n */\n userId?: string;\n /**\n * The location's property number.\n */\n propertyNumber?: string;\n /**\n * A link to the location's gate photo.\n */\n photo?: string;\n\n /**\n * A user's country\n */\n country?: string;\n\n /**\n * A user's city\n */\n city?: string;\n\n /**\n * A user's state\n */\n state?: string;\n\n /**\n * A formatted location information\n */\n displayTitle?: string;\n\n /**\n * A user's country code\n */\n countryCode?: string;\n}\n\n/**\n * @ignore\n */\nexport interface OkHiError {\n code: string;\n message: string;\n}\n\nexport type OkHiApplicationConfiguration = {\n credentials: {\n branchId: string;\n clientKey: string;\n };\n context: {\n mode: 'sandbox' | 'prod';\n developer?: 'okhi' | 'external';\n };\n app?: {\n name?: string;\n version?: string;\n build?: string;\n };\n notification?: {\n title: string;\n text: string;\n channelId: string;\n channelName: string;\n channelDescription: string;\n };\n};\n\nexport type LocationPermissionStatus =\n | 'notDetermined'\n | 'restricted'\n | 'denied'\n | 'authorizedAlways'\n | 'authorizedWhenInUse'\n | 'authorized'\n | 'unknown';\n\nexport type LocationPermissionStatusCallback =\n | LocationPermissionStatus\n | 'rationaleDissmissed';\nexport type LocationRequestPermissionType = 'whenInUse' | 'always';\n\nexport type LocationPermissionCallback = (\n status: LocationPermissionStatusCallback | null,\n error: OkHiError | null\n) => any;\n"],"mappings":""}
1
+ {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["/**\n * Defines the structure of the user object requried by OkHi services and libraries.\n */\nexport interface OkHiUser {\n /**\n * The user's phone number. Must be MSISDN standard format. e.g +254712345678.\n */\n phone: string;\n /**\n * The user's first name.\n */\n firstName?: string;\n /**\n * The user's last name.\n */\n lastName?: string;\n /**\n * The user's email address.\n */\n email?: string;\n /**\n * The OkHi's userId. Usually obtained after a user successfully creates an OkHi address.\n */\n id?: string;\n\n /**\n * The user's device firebase push notification token.\n */\n fcmPushNotificationToken?: string;\n}\n\n/**\n * Defines the current mode you'll be using OkHi's services as well as your application's meta information.\n */\nexport interface OkHiAppContext {\n /**\n * The current mode you'll be using OkHi services.\n */\n mode: 'sandbox' | 'prod' | string;\n /**\n * Your application's meta information.\n */\n app?: {\n /**\n * Your application's name.\n */\n name: string;\n /**\n * Your application's current version.\n */\n version: string;\n /**\n * Your application's current build number.\n */\n build: number;\n };\n /**\n * Meta information about the current developer.\n */\n developer?: string;\n}\n\n/**\n * Defines the structure of the OkHi location object once an address has been successfully created by the user.\n */\nexport interface OkHiLocation {\n /**\n * The latitude of the location.\n */\n lat: number;\n /**\n * The longitude of the location.\n */\n lon: number;\n /**\n * The OkHi's locationId. Usually obtained once an address has been successfully created by the user.\n */\n id?: string;\n /**\n * The id of a common residential or geological space such as apartment building or office block.\n */\n placeId?: string;\n /**\n * Geocode system for identifying an area anywhere on the Earth.\n * See https://plus.codes/\n */\n plusCode?: string;\n /**\n * The location's property name.\n */\n propertyName?: string;\n /**\n * The location's street name.\n */\n streetName?: string;\n /**\n * A string that can be used to render information about the location.\n */\n title?: string;\n /**\n * A string that can be used to render meta information about the location.\n */\n subtitle?: string;\n /**\n * User generated directions to the location.\n */\n directions?: string;\n /**\n * User generated meta information about the location, how to access it and any other relevant notes.\n */\n otherInformation?: string;\n /**\n * A link to the user's address visible on browser or desktop.\n */\n url?: string;\n /**\n * A Google's StreetView Panorama Id, if the address was created using Google StreetView.\n * See: https://developers.google.com/maps/documentation/javascript/streetview\n */\n streetViewPanoId?: string;\n /**\n * A Google's StreetView Panorama Url, if the address was created using Google StreetView.\n * See: https://developers.google.com/maps/documentation/javascript/streetview\n */\n streetViewPanoUrl?: string;\n /**\n * The OkHi's userId. Usually obtained after a user successfully creates an OkHi address.\n */\n userId?: string;\n /**\n * The location's property number.\n */\n propertyNumber?: string;\n /**\n * A link to the location's gate photo.\n */\n photo?: string;\n\n /**\n * A user's country\n */\n country?: string;\n\n /**\n * A user's city\n */\n city?: string;\n\n /**\n * A user's state\n */\n state?: string;\n\n /**\n * A formatted location information\n */\n displayTitle?: string;\n\n /**\n * A user's country code\n */\n countryCode?: string;\n}\n\n/**\n * @ignore\n */\nexport interface OkHiError {\n code: string;\n message: string;\n}\n\nexport type OkHiApplicationConfiguration = {\n credentials: {\n branchId: string;\n clientKey: string;\n };\n context: {\n mode: 'sandbox' | 'prod';\n developer?: 'okhi' | 'external';\n };\n app?: {\n name?: string;\n version?: string;\n build?: string;\n };\n notification?: {\n title: string;\n text: string;\n channelId: string;\n channelName: string;\n channelDescription: string;\n };\n};\n\nexport type LocationPermissionStatus =\n | 'notDetermined'\n | 'restricted'\n | 'denied'\n | 'authorizedAlways'\n | 'authorizedWhenInUse'\n | 'authorized'\n | 'unknown';\n\nexport type LocationPermissionStatusCallback =\n | LocationPermissionStatus\n | 'rationaleDissmissed';\nexport type LocationRequestPermissionType = 'whenInUse' | 'always';\n\nexport type LocationPermissionCallback = (\n status: LocationPermissionStatusCallback | null,\n error: OkHiError | null\n) => any;\n"],"mappings":""}
@@ -1 +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 ): 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};\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;AA8CO,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};\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;AAiDO,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"}
@@ -11,9 +11,11 @@ var _exportNames = {
11
11
  stopForegroundService: true,
12
12
  isForegroundServiceRunning: true,
13
13
  canStartVerification: true,
14
- checkVerificationStartRequirements: true
14
+ checkVerificationStartRequirements: true,
15
+ onNewToken: true,
16
+ onMessageReceived: true
15
17
  };
16
- exports.stopVerification = exports.stopForegroundService = exports.startVerification = exports.startForegroundService = exports.start = exports.isForegroundServiceRunning = exports.checkVerificationStartRequirements = exports.canStartVerification = void 0;
18
+ exports.stopVerification = exports.stopForegroundService = exports.startVerification = exports.startForegroundService = exports.start = exports.onNewToken = exports.onMessageReceived = exports.isForegroundServiceRunning = exports.checkVerificationStartRequirements = exports.canStartVerification = void 0;
17
19
 
18
20
  var _reactNative = require("react-native");
19
21
 
@@ -48,12 +50,13 @@ Object.keys(_types).forEach(function (key) {
48
50
  * @param {Object} configuration Configures how verification will start on different platforms
49
51
  * @param {Object} configuration.android Specifices how verification will start on Android platforms
50
52
  * @param {boolean} configuration.android.withForeground Specifices if the foreground service will be turned on to speed up rate of verification, default is true
53
+ * @param {string} fcmPushNotificationToken User's firebase push notification token
51
54
  * @returns {Promise<string>} A promise that resolves to a string value of the location identifier
52
55
  */
53
- const start = (phoneNumber, locationId, lat, lon, configuration) => {
56
+ const start = (phoneNumber, locationId, lat, lon, configuration, fcmPushNotificationToken) => {
54
57
  return (0, _helpers.isValidPlatform)(() => {
55
58
  if (_reactNative.Platform.OS === 'android') {
56
- return _OkHiNativeModule.OkHiNativeModule.startAddressVerification(phoneNumber, locationId, lat, lon, configuration);
59
+ return _OkHiNativeModule.OkHiNativeModule.startAddressVerification(phoneNumber, locationId, lat, lon, configuration, fcmPushNotificationToken);
57
60
  } else {
58
61
  return _OkHiNativeModule.OkHiNativeModule.startAddressVerification(phoneNumber, locationId, lat, lon);
59
62
  }
@@ -80,7 +83,7 @@ const startVerification = async (response, configuration) => {
80
83
 
81
84
  if (location.id) {
82
85
  if (_reactNative.Platform.OS === 'android') {
83
- const result = _OkHiNativeModule.OkHiNativeModule.startAddressVerification(user.phone, location.id, location.lat, location.lon, configuration);
86
+ const result = _OkHiNativeModule.OkHiNativeModule.startAddressVerification(user.phone, location.id, location.lat, location.lon, configuration, user.fcmPushNotificationToken);
84
87
 
85
88
  resolve(result);
86
89
  } else {
@@ -241,6 +244,28 @@ const checkVerificationStartRequirements = () => {
241
244
  resolve(true);
242
245
  });
243
246
  };
247
+ /**
248
+ * Android Only - Updates user's device firebase push notification token
249
+ * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service has started successfully
250
+ */
251
+
244
252
 
245
253
  exports.checkVerificationStartRequirements = checkVerificationStartRequirements;
254
+
255
+ const onNewToken = fcmPushNotificationToken => {
256
+ return (0, _helpers.isValidPlatform)(() => (0, _helpers.errorHandler)(() => _OkHiNativeModule.OkHiNativeModule.onNewToken(fcmPushNotificationToken)), 'android');
257
+ };
258
+ /**
259
+ * Android Only - Should be invoked only when push notification is received.
260
+ * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service has started successfully
261
+ */
262
+
263
+
264
+ exports.onNewToken = onNewToken;
265
+
266
+ const onMessageReceived = () => {
267
+ return (0, _helpers.isValidPlatform)(() => (0, _helpers.errorHandler)(_OkHiNativeModule.OkHiNativeModule.onMessageReceived), 'android');
268
+ };
269
+
270
+ exports.onMessageReceived = onMessageReceived;
246
271
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["start","phoneNumber","locationId","lat","lon","configuration","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"],"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 * @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) => {\n return isValidPlatform(() => {\n if (Platform.OS === 'android') {\n return OkHiNativeModule.startAddressVerification(\n phoneNumber,\n locationId,\n lat,\n lon,\n configuration\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 );\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"],"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;AACO,MAAMA,KAAK,GAAG,CACnBC,WADmB,EAEnBC,UAFmB,EAGnBC,GAHmB,EAInBC,GAJmB,EAKnBC,aALmB,KAMhB;EACH,OAAO,IAAAC,wBAAA,EAAgB,MAAM;IAC3B,IAAIC,qBAAA,CAASC,EAAT,KAAgB,SAApB,EAA+B;MAC7B,OAAOC,kCAAA,CAAiBC,wBAAjB,CACLT,WADK,EAELC,UAFK,EAGLC,GAHK,EAILC,GAJK,EAKLC,aALK,CAAP;IAOD,CARD,MAQO;MACL,OAAOI,kCAAA,CAAiBC,wBAAjB,CACLT,WADK,EAELC,UAFK,EAGLC,GAHK,EAILC,GAJK,CAAP;IAMD;EACF,CAjBM,CAAP;AAkBD,CAzBM;AA2BP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AACO,MAAMO,iBAAiB,GAAG,OAC/BC,QAD+B,EAE/BP,aAF+B,KAG5B;EACH,OAAO,IAAIQ,OAAJ,CAAY,CAACC,OAAD,EAAUC,MAAV,KAAqB;IACtC,MAAM;MAAEC,QAAF;MAAYC;IAAZ,IAAqBL,QAA3B;;IACA,IAAII,QAAQ,CAACE,EAAb,EAAiB;MACf,IAAIX,qBAAA,CAASC,EAAT,KAAgB,SAApB,EAA+B;QAC7B,MAAMW,MA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,CADI,CAAN;MAMA;IACD;;IACDV,OAAO,CAAC,IAAD,CAAP;EACD,CAhCM,CAAP;AAiCD,CAlCM"}
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,CAAP;IAQD,CATD,MASO;MACL,OAAOI,kCAAA,CAAiBC,wBAAjB,CACLV,WADK,EAELC,UAFK,EAGLC,GAHK,EAILC,GAJK,CAAP;IAMD;EACF,CAlBM,CAAP;AAmBD,CA3BM;AA6BP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AACO,MAAMQ,iBAAiB,GAAG,OAC/BC,QAD+B,EAE/BR,aAF+B,KAG5B;EACH,OAAO,IAAIS,OAAJ,CAAY,CAACC,OAAD,EAAUC,MAAV,KAAqB;IACtC,MAAM;MAAEC,QAAF;MAAYC;IAAZ,IAAqBL,QAA3B;;IACA,IAAII,QAAQ,CAACE,EAAb,EAAiB;MACf,IAAIX,qBAAA,CAASC,EAAT,KAAgB,SAApB,EAA+B;QAC7B,MAAMW,MAAM,GAAGV,kCAAA,CAAiBC,wB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ADI,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"}
@@ -88,7 +88,10 @@ export const OkHiLocationManager = props => {
88
88
  } else if (response.message === 'request_enable_protected_apps') {
89
89
  openProtectedAppsSettings();
90
90
  } else {
91
- onSuccess({ ...response.payload,
91
+ onSuccess({
92
+ user: { ...response.payload.user,
93
+ fcmPushNotificationToken: user.fcmPushNotificationToken
94
+ },
92
95
  location: parseOkHiLocation(response.payload.location),
93
96
  startVerification: function (config) {
94
97
  const createdUser = { ...this.user
@@ -102,7 +105,7 @@ export const OkHiLocationManager = props => {
102
105
  message: 'Missing location id from response'
103
106
  }));
104
107
  } else {
105
- sv(createdUser.phone, location.id, location.lat, location.lon, config).then(resolve).catch(reject);
108
+ sv(createdUser.phone, location.id, location.lat, location.lon, config, createdUser.fcmPushNotificationToken).then(resolve).catch(reject);
106
109
  }
107
110
  });
108
111
  }
@@ -1 +1 @@
1
- {"version":3,"names":["React","useState","useEffect","useRef","Modal","SafeAreaView","Platform","WebView","Spinner","getFrameUrl","generateJavaScriptStartScript","generateStartDataPayload","parseOkHiLocation","OkHiException","OkHiAuth","start","sv","getApplicationConfiguration","openProtectedAppsSettings","OkHiNativeModule","OkHiLocationManager","props","token","setToken","applicationConfiguration","setApplicationConfiguration","startPayload","setStartPaylaod","defaultStyle","flex","style","user","onSuccess","onCloseRequest","onError","loader","launch","webViewRef","phone","then","config","code","UNAUTHORIZED_CODE","message","UNAUTHORIZED_MESSAGE","auth","anonymousSignInWithPhoneNumber","catch","error","OS","Version","setItem","JSON","stringify","payload","url","console","handleOnMessage","nativeEvent","data","response","parse","UNKNOWN_ERROR_CODE","toString","location","startVerification","createdUser","Promise","resolve","reject","id","BAD_REQUEST_CODE","lat","lon","errorMessage","Error","handleOnError","NETWORK_ERROR_CODE","NETWORK_ERROR_MESSAGE","handleModalRequestClose","current","goBack","renderContent","jsAfterLoad","jsBeforeLoad","uri","undefined"],"sources":["OkHiLocationManager.tsx"],"sourcesContent":["import React, { useState, useEffect, useRef } from 'react';\nimport { Modal, SafeAreaView, Platform } from 'react-native';\nimport { WebView, WebViewMessageEvent } from 'react-native-webview';\nimport { Spinner } from './Spinner';\nimport type {\n OkHiLocationManagerResponse,\n OkHiLocationManagerProps,\n OkHiLocationManagerStartDataPayload,\n} from './types';\nimport {\n getFrameUrl,\n generateJavaScriptStartScript,\n generateStartDataPayload,\n parseOkHiLocation,\n} from './Util';\nimport { OkHiException } from '../OkCore/OkHiException';\nimport { OkHiAuth } from '../OkCore/OkHiAuth';\nimport type { AuthApplicationConfig } from '../OkCore/_types';\nimport { start as sv } from '../OkVerify';\nimport type { OkVerifyStartConfiguration } from '../OkVerify/types';\nimport {\n getApplicationConfiguration,\n openProtectedAppsSettings,\n} from '../OkCore';\nimport { OkHiNativeModule } from '../OkHiNativeModule';\n\n/**\n * The OkHiLocationManager React Component is used to display an in app modal, enabling the user to quickly create an accurate OkHi address.\n */\nexport const OkHiLocationManager = (props: OkHiLocationManagerProps) => {\n const [token, setToken] = useState<string | null>(null);\n const [applicationConfiguration, setApplicationConfiguration] =\n useState<AuthApplicationConfig | null>(null);\n const [startPayload, setStartPaylaod] =\n useState<null | OkHiLocationManagerStartDataPayload>(null);\n const defaultStyle = { flex: 1 };\n const style = props.style\n ? { ...props.style, ...defaultStyle }\n : defaultStyle;\n\n const { user, onSuccess, onCloseRequest, onError, loader, launch } = props;\n const webViewRef = useRef<WebView | null>(null);\n\n useEffect(() => {\n if (applicationConfiguration == null && token == null && user.phone) {\n getApplicationConfiguration()\n .then((config) => {\n if (!config && launch) {\n onError(\n new OkHiException({\n code: OkHiException.UNAUTHORIZED_CODE,\n message: OkHiException.UNAUTHORIZED_MESSAGE,\n })\n );\n } else if (config) {\n setApplicationConfiguration(config);\n const auth = new OkHiAuth();\n auth\n .anonymousSignInWithPhoneNumber(user.phone, ['verify'], config)\n .then(setToken)\n .catch(onError);\n }\n })\n .catch((error) => {\n if (launch) {\n onError(error);\n }\n });\n }\n }, [onError, user.phone, launch, applicationConfiguration, token]);\n\n useEffect(() => {\n if (token !== null && applicationConfiguration !== null) {\n // TODO: handle faliure\n generateStartDataPayload(props, token, applicationConfiguration)\n .then((startPayload) => {\n setStartPaylaod(startPayload);\n if (Platform.OS === 'android' && Platform.Version > 25) {\n OkHiNativeModule.setItem(\n 'okcollect-launch-payload',\n JSON.stringify({\n message: 'select_location',\n payload: startPayload,\n url: getFrameUrl(applicationConfiguration),\n })\n ).catch(console.error);\n }\n })\n .catch(console.error);\n }\n }, [applicationConfiguration, props, token]);\n\n const handleOnMessage = ({ nativeEvent: { data } }: WebViewMessageEvent) => {\n try {\n const response: OkHiLocationManagerResponse = JSON.parse(data);\n if (response.message === 'fatal_exit') {\n onError(\n new OkHiException({\n code: OkHiException.UNKNOWN_ERROR_CODE,\n message: response.payload.toString(),\n })\n );\n } else if (response.message === 'exit_app') {\n onCloseRequest();\n } else if (response.message === 'request_enable_protected_apps') {\n openProtectedAppsSettings();\n } else {\n onSuccess({\n ...response.payload,\n location: parseOkHiLocation(response.payload.location),\n startVerification: function (config?: OkVerifyStartConfiguration) {\n const createdUser = { ...this.user };\n const location = { ...this.location };\n return new Promise((resolve, reject) => {\n if (!location.id) {\n reject(\n new OkHiException({\n code: OkHiException.BAD_REQUEST_CODE,\n message: 'Missing location id from response',\n })\n );\n } else {\n sv(\n createdUser.phone,\n location.id,\n location.lat,\n location.lon,\n config\n )\n .then(resolve)\n .catch(reject);\n }\n });\n },\n });\n }\n } catch (error) {\n let errorMessage = 'Something went wrong';\n if (error instanceof Error) {\n errorMessage = error.message;\n }\n onError(\n new OkHiException({\n code: OkHiException.UNKNOWN_ERROR_CODE,\n message: errorMessage,\n })\n );\n }\n };\n\n const handleOnError = () => {\n onError(\n new OkHiException({\n code: OkHiException.NETWORK_ERROR_CODE,\n message: OkHiException.NETWORK_ERROR_MESSAGE,\n })\n );\n };\n\n const handleModalRequestClose = () => {\n webViewRef.current?.goBack();\n };\n\n const renderContent = () => {\n if (token === null || applicationConfiguration == null) {\n return loader || <Spinner />;\n }\n\n if (startPayload === null) {\n return loader || <Spinner />;\n }\n\n const { jsAfterLoad, jsBeforeLoad } = generateJavaScriptStartScript({\n message: 'select_location',\n payload: startPayload,\n });\n\n return (\n <SafeAreaView style={style}>\n <WebView\n source={{ uri: getFrameUrl(applicationConfiguration) }}\n injectedJavaScriptBeforeContentLoaded={\n Platform.OS === 'ios' ? jsBeforeLoad : undefined\n }\n injectedJavaScript={Platform.OS === 'ios' ? undefined : jsAfterLoad}\n onMessage={handleOnMessage}\n onError={handleOnError}\n onHttpError={handleOnError}\n geolocationEnabled={true}\n allowsBackForwardNavigationGestures={true}\n ref={webViewRef}\n />\n </SafeAreaView>\n );\n };\n\n return (\n <Modal\n animationType=\"slide\"\n transparent={false}\n visible={launch}\n onRequestClose={handleModalRequestClose}\n >\n {launch ? renderContent() : null}\n </Modal>\n );\n};\n\nexport default OkHiLocationManager;\n"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,QAAhB,EAA0BC,SAA1B,EAAqCC,MAArC,QAAmD,OAAnD;AACA,SAASC,KAAT,EAAgBC,YAAhB,EAA8BC,QAA9B,QAA8C,cAA9C;AACA,SAASC,OAAT,QAA6C,sBAA7C;AACA,SAASC,OAAT,QAAwB,WAAxB;AAMA,SACEC,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AAE;QAAEuD,GAAG,EAAE5E,WAAW,CAACe,wBAAD;MAAlB,CADV;MAEE,qCAAqC,EACnClB,QAAQ,CAAC2C,EAAT,KAAgB,KAAhB,GAAwBmC,YAAxB,GAAuCE,SAH3C;MAKE,kBAAkB,EAAEhF,QAAQ,CAAC2C,EAAT,KAAgB,KAAhB,GAAwBqC,SAAxB,GAAoCH,WAL1D;MAME,SAAS,EAAE1B,eANb;MAOE,OAAO,EAAEmB,aAPX;MAQE,WAAW,EAAEA,aARf;MASE,kBAAkB,EAAE,IATtB;MAUE,mCAAmC,EAAE,IAVvC;MAWE,GAAG,EAAEvC;IAXP,EADF,CADF;EAiBD,CA/BD;;EAiCA,oBACE,oBAAC,KAAD;IACE,aAAa,EAAC,OADhB;IAEE,WAAW,EAAE,KAFf;IAGE,OAAO,EAAED,MAHX;IAIE,cAAc,EAAE2C;EAJlB,GAMG3C,MAAM,GAAG8C,aAAa,EAAhB,GAAqB,IAN9B,CADF;AAUD,CAjLM;AAmLP,eAAe9D,mBAAf"}
1
+ {"version":3,"names":["React","useState","useEffect","useRef","Modal","SafeAreaView","Platform","WebView","Spinner","getFrameUrl","generateJavaScriptStartScript","generateStartDataPayload","parseOkHiLocation","OkHiException","OkHiAuth","start","sv","getApplicationConfiguration","openProtectedAppsSettings","OkHiNativeModule","OkHiLocationManager","props","token","setToken","applicationConfiguration","setApplicationConfiguration","startPayload","setStartPaylaod","defaultStyle","flex","style","user","onSuccess","onCloseRequest","onError","loader","launch","webViewRef","phone","then","config","code","UNAUTHORIZED_CODE","message","UNAUTHORIZED_MESSAGE","auth","anonymousSignInWithPhoneNumber","catch","error","OS","Version","setItem","JSON","stringify","payload","url","console","handleOnMessage","nativeEvent","data","response","parse","UNKNOWN_ERROR_CODE","toString","fcmPushNotificationToken","location","startVerification","createdUser","Promise","resolve","reject","id","BAD_REQUEST_CODE","lat","lon","errorMessage","Error","handleOnError","NETWORK_ERROR_CODE","NETWORK_ERROR_MESSAGE","handleModalRequestClose","current","goBack","renderContent","jsAfterLoad","jsBeforeLoad","uri","undefined"],"sources":["OkHiLocationManager.tsx"],"sourcesContent":["import React, { useState, useEffect, useRef } from 'react';\nimport { Modal, SafeAreaView, Platform } from 'react-native';\nimport { WebView, WebViewMessageEvent } from 'react-native-webview';\nimport { Spinner } from './Spinner';\nimport type {\n OkHiLocationManagerResponse,\n OkHiLocationManagerProps,\n OkHiLocationManagerStartDataPayload,\n} from './types';\nimport {\n getFrameUrl,\n generateJavaScriptStartScript,\n generateStartDataPayload,\n parseOkHiLocation,\n} from './Util';\nimport { OkHiException } from '../OkCore/OkHiException';\nimport { OkHiAuth } from '../OkCore/OkHiAuth';\nimport type { AuthApplicationConfig } from '../OkCore/_types';\nimport { start as sv } from '../OkVerify';\nimport type { OkVerifyStartConfiguration } from '../OkVerify/types';\nimport {\n getApplicationConfiguration,\n openProtectedAppsSettings,\n} from '../OkCore';\nimport { OkHiNativeModule } from '../OkHiNativeModule';\n\n/**\n * The OkHiLocationManager React Component is used to display an in app modal, enabling the user to quickly create an accurate OkHi address.\n */\nexport const OkHiLocationManager = (props: OkHiLocationManagerProps) => {\n const [token, setToken] = useState<string | null>(null);\n const [applicationConfiguration, setApplicationConfiguration] =\n useState<AuthApplicationConfig | null>(null);\n const [startPayload, setStartPaylaod] =\n useState<null | OkHiLocationManagerStartDataPayload>(null);\n const defaultStyle = { flex: 1 };\n const style = props.style\n ? { ...props.style, ...defaultStyle }\n : defaultStyle;\n\n const { user, onSuccess, onCloseRequest, onError, loader, launch } = props;\n const webViewRef = useRef<WebView | null>(null);\n\n useEffect(() => {\n if (applicationConfiguration == null && token == null && user.phone) {\n getApplicationConfiguration()\n .then((config) => {\n if (!config && launch) {\n onError(\n new OkHiException({\n code: OkHiException.UNAUTHORIZED_CODE,\n message: OkHiException.UNAUTHORIZED_MESSAGE,\n })\n );\n } else if (config) {\n setApplicationConfiguration(config);\n const auth = new OkHiAuth();\n auth\n .anonymousSignInWithPhoneNumber(user.phone, ['verify'], config)\n .then(setToken)\n .catch(onError);\n }\n })\n .catch((error) => {\n if (launch) {\n onError(error);\n }\n });\n }\n }, [onError, user.phone, launch, applicationConfiguration, token]);\n\n useEffect(() => {\n if (token !== null && applicationConfiguration !== null) {\n // TODO: handle faliure\n generateStartDataPayload(props, token, applicationConfiguration)\n .then((startPayload) => {\n setStartPaylaod(startPayload);\n if (Platform.OS === 'android' && Platform.Version > 25) {\n OkHiNativeModule.setItem(\n 'okcollect-launch-payload',\n JSON.stringify({\n message: 'select_location',\n payload: startPayload,\n url: getFrameUrl(applicationConfiguration),\n })\n ).catch(console.error);\n }\n })\n .catch(console.error);\n }\n }, [applicationConfiguration, props, token]);\n\n const handleOnMessage = ({ nativeEvent: { data } }: WebViewMessageEvent) => {\n try {\n const response: OkHiLocationManagerResponse = JSON.parse(data);\n if (response.message === 'fatal_exit') {\n onError(\n new OkHiException({\n code: OkHiException.UNKNOWN_ERROR_CODE,\n message: response.payload.toString(),\n })\n );\n } else if (response.message === 'exit_app') {\n onCloseRequest();\n } else if (response.message === 'request_enable_protected_apps') {\n openProtectedAppsSettings();\n } else {\n onSuccess({\n user: {\n ...response.payload.user,\n fcmPushNotificationToken: user.fcmPushNotificationToken,\n },\n location: parseOkHiLocation(response.payload.location),\n startVerification: function (config?: OkVerifyStartConfiguration) {\n const createdUser = { ...this.user };\n const location = { ...this.location };\n return new Promise((resolve, reject) => {\n if (!location.id) {\n reject(\n new OkHiException({\n code: OkHiException.BAD_REQUEST_CODE,\n message: 'Missing location id from response',\n })\n );\n } else {\n sv(\n createdUser.phone,\n location.id,\n location.lat,\n location.lon,\n config,\n createdUser.fcmPushNotificationToken\n )\n .then(resolve)\n .catch(reject);\n }\n });\n },\n });\n }\n } catch (error) {\n let errorMessage = 'Something went wrong';\n if (error instanceof Error) {\n errorMessage = error.message;\n }\n onError(\n new OkHiException({\n code: OkHiException.UNKNOWN_ERROR_CODE,\n message: errorMessage,\n })\n );\n }\n };\n\n const handleOnError = () => {\n onError(\n new OkHiException({\n code: OkHiException.NETWORK_ERROR_CODE,\n message: OkHiException.NETWORK_ERROR_MESSAGE,\n })\n );\n };\n\n const handleModalRequestClose = () => {\n webViewRef.current?.goBack();\n };\n\n const renderContent = () => {\n if (token === null || applicationConfiguration == null) {\n return loader || <Spinner />;\n }\n\n if (startPayload === null) {\n return loader || <Spinner />;\n }\n\n const { jsAfterLoad, jsBeforeLoad } = generateJavaScriptStartScript({\n message: 'select_location',\n payload: startPayload,\n });\n\n return (\n <SafeAreaView style={style}>\n <WebView\n source={{ uri: getFrameUrl(applicationConfiguration) }}\n injectedJavaScriptBeforeContentLoaded={\n Platform.OS === 'ios' ? jsBeforeLoad : undefined\n }\n injectedJavaScript={Platform.OS === 'ios' ? undefined : jsAfterLoad}\n onMessage={handleOnMessage}\n onError={handleOnError}\n onHttpError={handleOnError}\n geolocationEnabled={true}\n allowsBackForwardNavigationGestures={true}\n ref={webViewRef}\n />\n </SafeAreaView>\n );\n };\n\n return (\n <Modal\n animationType=\"slide\"\n transparent={false}\n visible={launch}\n onRequestClose={handleModalRequestClose}\n >\n {launch ? renderContent() : null}\n </Modal>\n );\n};\n\nexport default OkHiLocationManager;\n"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,QAAhB,EAA0BC,SAA1B,EAAqCC,MAArC,QAAmD,OAAnD;AACA,SAASC,KAAT,EAAgBC,YAAhB,EAA8BC,QAA9B,QAA8C,cAA9C;AACA,SAASC,OAAT,QAA6C,sBAA7C;AACA,SAASC,OAAT,QAAwB,WAAxB;AAMA,SACEC,WADF,EAEEC,6BAFF,EAGEC,wBAHF,EAIEC,iBAJF,QAKO,QALP;AAMA,SAASC,aAAT,QAA8B,yBAA9B;AACA,SAASC,QAAT,QAAyB,oBAAzB;AAEA,SAASC,KAAK,IAAIC,EAAlB,QAA4B,aAA5B;AAEA,SACEC,2BADF,EAEEC,yBAFF,QAGO,WAHP;AAIA,SAASC,gBAAT,QAAiC,qBAAjC;AAEA;AACA;AACA;;AACA,OAAO,M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,QAAQ,CAAC2C,EAAT,KAAgB,KAAhB,GAAwBsC,SAAxB,GAAoCH,WAL1D;MAME,SAAS,EAAE3B,eANb;MAOE,OAAO,EAAEoB,aAPX;MAQE,WAAW,EAAEA,aARf;MASE,kBAAkB,EAAE,IATtB;MAUE,mCAAmC,EAAE,IAVvC;MAWE,GAAG,EAAExC;IAXP,EADF,CADF;EAiBD,CA/BD;;EAiCA,oBACE,oBAAC,KAAD;IACE,aAAa,EAAC,OADhB;IAEE,WAAW,EAAE,KAFf;IAGE,OAAO,EAAED,MAHX;IAIE,cAAc,EAAE4C;EAJlB,GAMG5C,MAAM,GAAG+C,aAAa,EAAhB,GAAqB,IAN9B,CADF;AAUD,CArLM;AAuLP,eAAe/D,mBAAf"}
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "okhiWebReactNative",
3
- "version": "1.1.1-beta.1"
3
+ "version": "1.1.1-beta.4"
4
4
  }
@@ -4,6 +4,7 @@ import axios from 'axios';
4
4
  import { OkHiMode } from './OkHiMode';
5
5
  import { OkHiException } from './OkHiException';
6
6
  import { getApplicationConfiguration } from './';
7
+ import { OkHiNativeModule } from '../OkHiNativeModule';
7
8
  /**
8
9
  * @ignore
9
10
  */
@@ -71,6 +72,8 @@ export class OkHiAuth {
71
72
  } = await axios.post(url, payload, {
72
73
  headers
73
74
  });
75
+ await OkHiNativeModule.setItem('okhi:recent:token', data.authorization_token); //TODO: move all anonymousSignIn to native code
76
+
74
77
  resolve(data.authorization_token);
75
78
  }
76
79
  } catch (error) {
@@ -1 +1 @@
1
- {"version":3,"names":["axios","OkHiMode","OkHiException","getApplicationConfiguration","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","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 './';\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 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;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,K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MlC,KAAK,CAACmC,IAAN,CAAWT,GAAX,EAAgBX,OAAhB,EAAyB;YAC9CiB;UAD8C,CAAzB,CAAvB;UAGAf,OAAO,CAACiB,IAAI,CAACE,mBAAN,CAAP;QACD;MACF,CAzBD,CAyBE,OAAOC,KAAP,EAAc;QACdnB,MAAM,CAAC,KAAKoB,iBAAL,CAAuBD,KAAvB,CAAD,CAAN;MACD;IACF,CA7BM,CAAP;EA8BD;;EAEOC,iBAAiB,CAACD,KAAD,EAAa;IACpC,IAAI,CAACA,KAAK,CAACE,QAAX,EAAqB;MACnB,OAAO,IAAIrC,aAAJ,CAAkB;QACvBmB,IAAI,EAAEnB,aAAa,CAACsC,kBADG;QAEvBjB,OAAO,EAAErB,aAAa,CAACuC;MAFA,CAAlB,CAAP;IAID;;IACD,QAAQJ,KAAK,CAACE,QAAN,CAAeG,MAAvB;MACE,KAAK,GAAL;QACE,OAAO,IAAIxC,aAAJ,CAAkB;UACvBmB,IAAI,EAAEnB,aAAa,CAACyC,kBADG;UAEvBpB,OAAO,EAAErB,aAAa,CAAC0C;QAFA,CAAlB,CAAP;;MAIF,KAAK,GAAL;QACE,OAAO,IAAI1C,aAAJ,CAAkB;UACvBmB,IAAI,EAAEnB,aAAa,CAACoB,iBADG;UAEvBC,OAAO,EAAErB,aAAa,CAACsB;QAFA,CAAlB,CAAP;;MAIF;QACE,OAAO,IAAItB,aAAJ,CAAkB;UACvBmB,IAAI,EAAEnB,aAAa,CAAC2C,kBADG;UAEvBtB,OAAO,EAAEc,KAAK,CAACd,OAAN,IAAiBrB,aAAa,CAAC4C;QAFjB,CAAlB,CAAP;IAZJ;EAiBD;;AA/FmB"}
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,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Aa,CAAC6C,kBADG;UAEvBvB,OAAO,EAAEe,KAAK,CAACf,OAAN,IAAiBtB,aAAa,CAAC8C;QAFjB,CAAlB,CAAP;IAZJ;EAiBD;;AAnGmB"}
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["/**\n * Defines the structure of the user object requried by OkHi services and libraries.\n */\nexport interface OkHiUser {\n /**\n * The user's phone number. Must be MSISDN standard format. e.g +254712345678.\n */\n phone: string;\n /**\n * The user's first name.\n */\n firstName?: string;\n /**\n * The user's last name.\n */\n lastName?: string;\n /**\n * The user's email address.\n */\n email?: string;\n /**\n * The OkHi's userId. Usually obtained after a user successfully creates an OkHi address.\n */\n id?: string;\n}\n\n/**\n * Defines the current mode you'll be using OkHi's services as well as your application's meta information.\n */\nexport interface OkHiAppContext {\n /**\n * The current mode you'll be using OkHi services.\n */\n mode: 'sandbox' | 'prod' | string;\n /**\n * Your application's meta information.\n */\n app?: {\n /**\n * Your application's name.\n */\n name: string;\n /**\n * Your application's current version.\n */\n version: string;\n /**\n * Your application's current build number.\n */\n build: number;\n };\n /**\n * Meta information about the current developer.\n */\n developer?: string;\n}\n\n/**\n * Defines the structure of the OkHi location object once an address has been successfully created by the user.\n */\nexport interface OkHiLocation {\n /**\n * The latitude of the location.\n */\n lat: number;\n /**\n * The longitude of the location.\n */\n lon: number;\n /**\n * The OkHi's locationId. Usually obtained once an address has been successfully created by the user.\n */\n id?: string;\n /**\n * The id of a common residential or geological space such as apartment building or office block.\n */\n placeId?: string;\n /**\n * Geocode system for identifying an area anywhere on the Earth.\n * See https://plus.codes/\n */\n plusCode?: string;\n /**\n * The location's property name.\n */\n propertyName?: string;\n /**\n * The location's street name.\n */\n streetName?: string;\n /**\n * A string that can be used to render information about the location.\n */\n title?: string;\n /**\n * A string that can be used to render meta information about the location.\n */\n subtitle?: string;\n /**\n * User generated directions to the location.\n */\n directions?: string;\n /**\n * User generated meta information about the location, how to access it and any other relevant notes.\n */\n otherInformation?: string;\n /**\n * A link to the user's address visible on browser or desktop.\n */\n url?: string;\n /**\n * A Google's StreetView Panorama Id, if the address was created using Google StreetView.\n * See: https://developers.google.com/maps/documentation/javascript/streetview\n */\n streetViewPanoId?: string;\n /**\n * A Google's StreetView Panorama Url, if the address was created using Google StreetView.\n * See: https://developers.google.com/maps/documentation/javascript/streetview\n */\n streetViewPanoUrl?: string;\n /**\n * The OkHi's userId. Usually obtained after a user successfully creates an OkHi address.\n */\n userId?: string;\n /**\n * The location's property number.\n */\n propertyNumber?: string;\n /**\n * A link to the location's gate photo.\n */\n photo?: string;\n\n /**\n * A user's country\n */\n country?: string;\n\n /**\n * A user's city\n */\n city?: string;\n\n /**\n * A user's state\n */\n state?: string;\n\n /**\n * A formatted location information\n */\n displayTitle?: string;\n\n /**\n * A user's country code\n */\n countryCode?: string;\n}\n\n/**\n * @ignore\n */\nexport interface OkHiError {\n code: string;\n message: string;\n}\n\nexport type OkHiApplicationConfiguration = {\n credentials: {\n branchId: string;\n clientKey: string;\n };\n context: {\n mode: 'sandbox' | 'prod';\n developer?: 'okhi' | 'external';\n };\n app?: {\n name?: string;\n version?: string;\n build?: string;\n };\n notification?: {\n title: string;\n text: string;\n channelId: string;\n channelName: string;\n channelDescription: string;\n };\n};\n\nexport type LocationPermissionStatus =\n | 'notDetermined'\n | 'restricted'\n | 'denied'\n | 'authorizedAlways'\n | 'authorizedWhenInUse'\n | 'authorized'\n | 'unknown';\n\nexport type LocationPermissionStatusCallback =\n | LocationPermissionStatus\n | 'rationaleDissmissed';\nexport type LocationRequestPermissionType = 'whenInUse' | 'always';\n\nexport type LocationPermissionCallback = (\n status: LocationPermissionStatusCallback | null,\n error: OkHiError | null\n) => any;\n"],"mappings":""}
1
+ {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["/**\n * Defines the structure of the user object requried by OkHi services and libraries.\n */\nexport interface OkHiUser {\n /**\n * The user's phone number. Must be MSISDN standard format. e.g +254712345678.\n */\n phone: string;\n /**\n * The user's first name.\n */\n firstName?: string;\n /**\n * The user's last name.\n */\n lastName?: string;\n /**\n * The user's email address.\n */\n email?: string;\n /**\n * The OkHi's userId. Usually obtained after a user successfully creates an OkHi address.\n */\n id?: string;\n\n /**\n * The user's device firebase push notification token.\n */\n fcmPushNotificationToken?: string;\n}\n\n/**\n * Defines the current mode you'll be using OkHi's services as well as your application's meta information.\n */\nexport interface OkHiAppContext {\n /**\n * The current mode you'll be using OkHi services.\n */\n mode: 'sandbox' | 'prod' | string;\n /**\n * Your application's meta information.\n */\n app?: {\n /**\n * Your application's name.\n */\n name: string;\n /**\n * Your application's current version.\n */\n version: string;\n /**\n * Your application's current build number.\n */\n build: number;\n };\n /**\n * Meta information about the current developer.\n */\n developer?: string;\n}\n\n/**\n * Defines the structure of the OkHi location object once an address has been successfully created by the user.\n */\nexport interface OkHiLocation {\n /**\n * The latitude of the location.\n */\n lat: number;\n /**\n * The longitude of the location.\n */\n lon: number;\n /**\n * The OkHi's locationId. Usually obtained once an address has been successfully created by the user.\n */\n id?: string;\n /**\n * The id of a common residential or geological space such as apartment building or office block.\n */\n placeId?: string;\n /**\n * Geocode system for identifying an area anywhere on the Earth.\n * See https://plus.codes/\n */\n plusCode?: string;\n /**\n * The location's property name.\n */\n propertyName?: string;\n /**\n * The location's street name.\n */\n streetName?: string;\n /**\n * A string that can be used to render information about the location.\n */\n title?: string;\n /**\n * A string that can be used to render meta information about the location.\n */\n subtitle?: string;\n /**\n * User generated directions to the location.\n */\n directions?: string;\n /**\n * User generated meta information about the location, how to access it and any other relevant notes.\n */\n otherInformation?: string;\n /**\n * A link to the user's address visible on browser or desktop.\n */\n url?: string;\n /**\n * A Google's StreetView Panorama Id, if the address was created using Google StreetView.\n * See: https://developers.google.com/maps/documentation/javascript/streetview\n */\n streetViewPanoId?: string;\n /**\n * A Google's StreetView Panorama Url, if the address was created using Google StreetView.\n * See: https://developers.google.com/maps/documentation/javascript/streetview\n */\n streetViewPanoUrl?: string;\n /**\n * The OkHi's userId. Usually obtained after a user successfully creates an OkHi address.\n */\n userId?: string;\n /**\n * The location's property number.\n */\n propertyNumber?: string;\n /**\n * A link to the location's gate photo.\n */\n photo?: string;\n\n /**\n * A user's country\n */\n country?: string;\n\n /**\n * A user's city\n */\n city?: string;\n\n /**\n * A user's state\n */\n state?: string;\n\n /**\n * A formatted location information\n */\n displayTitle?: string;\n\n /**\n * A user's country code\n */\n countryCode?: string;\n}\n\n/**\n * @ignore\n */\nexport interface OkHiError {\n code: string;\n message: string;\n}\n\nexport type OkHiApplicationConfiguration = {\n credentials: {\n branchId: string;\n clientKey: string;\n };\n context: {\n mode: 'sandbox' | 'prod';\n developer?: 'okhi' | 'external';\n };\n app?: {\n name?: string;\n version?: string;\n build?: string;\n };\n notification?: {\n title: string;\n text: string;\n channelId: string;\n channelName: string;\n channelDescription: string;\n };\n};\n\nexport type LocationPermissionStatus =\n | 'notDetermined'\n | 'restricted'\n | 'denied'\n | 'authorizedAlways'\n | 'authorizedWhenInUse'\n | 'authorized'\n | 'unknown';\n\nexport type LocationPermissionStatusCallback =\n | LocationPermissionStatus\n | 'rationaleDissmissed';\nexport type LocationRequestPermissionType = 'whenInUse' | 'always';\n\nexport type LocationPermissionCallback = (\n status: LocationPermissionStatusCallback | null,\n error: OkHiError | null\n) => any;\n"],"mappings":""}
@@ -1 +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 ): 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};\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;AA8CA,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};\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;AAiDA,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"}
@@ -13,13 +13,14 @@ export * from './types';
13
13
  * @param {Object} configuration Configures how verification will start on different platforms
14
14
  * @param {Object} configuration.android Specifices how verification will start on Android platforms
15
15
  * @param {boolean} configuration.android.withForeground Specifices if the foreground service will be turned on to speed up rate of verification, default is true
16
+ * @param {string} fcmPushNotificationToken User's firebase push notification token
16
17
  * @returns {Promise<string>} A promise that resolves to a string value of the location identifier
17
18
  */
18
19
 
19
- export const start = (phoneNumber, locationId, lat, lon, configuration) => {
20
+ export const start = (phoneNumber, locationId, lat, lon, configuration, fcmPushNotificationToken) => {
20
21
  return isValidPlatform(() => {
21
22
  if (Platform.OS === 'android') {
22
- return OkHiNativeModule.startAddressVerification(phoneNumber, locationId, lat, lon, configuration);
23
+ return OkHiNativeModule.startAddressVerification(phoneNumber, locationId, lat, lon, configuration, fcmPushNotificationToken);
23
24
  } else {
24
25
  return OkHiNativeModule.startAddressVerification(phoneNumber, locationId, lat, lon);
25
26
  }
@@ -43,7 +44,7 @@ export const startVerification = async (response, configuration) => {
43
44
 
44
45
  if (location.id) {
45
46
  if (Platform.OS === 'android') {
46
- const result = OkHiNativeModule.startAddressVerification(user.phone, location.id, location.lat, location.lon, configuration);
47
+ const result = OkHiNativeModule.startAddressVerification(user.phone, location.id, location.lat, location.lon, configuration, user.fcmPushNotificationToken);
47
48
  resolve(result);
48
49
  } else {
49
50
  const result = OkHiNativeModule.startAddressVerification(user.phone, location.id, location.lat, location.lon);
@@ -184,4 +185,20 @@ export const checkVerificationStartRequirements = () => {
184
185
  resolve(true);
185
186
  });
186
187
  };
188
+ /**
189
+ * Android Only - Updates user's device firebase push notification token
190
+ * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service has started successfully
191
+ */
192
+
193
+ export const onNewToken = fcmPushNotificationToken => {
194
+ return isValidPlatform(() => errorHandler(() => OkHiNativeModule.onNewToken(fcmPushNotificationToken)), 'android');
195
+ };
196
+ /**
197
+ * Android Only - Should be invoked only when push notification is received.
198
+ * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service has started successfully
199
+ */
200
+
201
+ export const onMessageReceived = () => {
202
+ return isValidPlatform(() => errorHandler(OkHiNativeModule.onMessageReceived), 'android');
203
+ };
187
204
  //# 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","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"],"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 * @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) => {\n return isValidPlatform(() => {\n if (Platform.OS === 'android') {\n return OkHiNativeModule.startAddressVerification(\n phoneNumber,\n locationId,\n lat,\n lon,\n configuration\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 );\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"],"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,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FP,CAAlB,CADI,CAAN;IAMD;EACF,CAnDM,CAAP;AAoDD,CAvDM;AAyDP;AACA;AACA;AACA;;AACA,OAAO,MAAMC,kCAAkC,GAAG,MAAwB;EACxE,OAAO,IAAI7B,OAAJ,CAAY,OAAOC,OAAP,EAAgBC,MAAhB,KAA2B;IAC5C,IAAIzB,QAAQ,CAACmB,EAAT,KAAgB,SAApB,EAA+B;MAC7B,MAAMkC,uBAAuB,GAAG,MAAMnD,6BAA6B,EAAnE;;MACA,IAAI,CAACmD,uBAAL,EAA8B;QAC5B5B,MAAM,CACJ,IAAIb,aAAJ,CAAkB;UAChBmB,IAAI,EAAEnB,aAAa,CAAC0C,8BADJ;UAEhBrB,OAAO,EAAE;QAFO,CAAlB,CADI,CAAN;QAMA;MACD;IACF;;IACD,IAAI,EAAE,MAAM9B,yBAAyB,EAAjC,CAAJ,EAA0C;MACxCsB,MAAM,CACJ,IAAIb,aAAJ,CAAkB;QAChBmB,IAAI,EAAEnB,aAAa,CAAC2C,kCADJ;QAEhBtB,OAAO,EAAE;MAFO,CAAlB,CADI,CAAN;MAMA;IACD;;IACD,IAAI,EAAE,MAAMhC,qCAAqC,EAA7C,CAAJ,EAAsD;MACpDwB,MAAM,CACJ,IAAIb,aAAJ,CAAkB;QAChBmB,IAAI,EAAEnB,aAAa,CAAC4C,sBADJ;QAEhBvB,OAAO,EAAE;MAFO,CAAlB,CADI,CAAN;MAMA;IACD;;IACDT,OAAO,CAAC,IAAD,CAAP;EACD,CAhCM,CAAP;AAiCD,CAlCM"}
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,SA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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"}
@@ -22,6 +22,10 @@ export interface OkHiUser {
22
22
  * The OkHi's userId. Usually obtained after a user successfully creates an OkHi address.
23
23
  */
24
24
  id?: string;
25
+ /**
26
+ * The user's device firebase push notification token.
27
+ */
28
+ fcmPushNotificationToken?: string;
25
29
  }
26
30
  /**
27
31
  * Defines the current mode you'll be using OkHi's services as well as your application's meta information.
@@ -12,7 +12,7 @@ declare type OkHiNativeModuleType = {
12
12
  getSystemVersion(): Promise<number | string>;
13
13
  getAuthToken(branchId: string, clientKey: string): Promise<string>;
14
14
  initialize(configuration: string): Promise<void>;
15
- startAddressVerification(phoneNumber: string, locationId: string, lat: Number, lon: Number, configuration?: OkVerifyStartConfiguration): Promise<string>;
15
+ startAddressVerification(phoneNumber: string, locationId: string, lat: Number, lon: Number, configuration?: OkVerifyStartConfiguration, fcmPushNotificationToken?: string): Promise<string>;
16
16
  stopAddressVerification(phoneNumber: string, locationId: string): Promise<string>;
17
17
  startForegroundService(): Promise<boolean>;
18
18
  stopForegroundService(): Promise<boolean>;
@@ -28,6 +28,8 @@ declare type OkHiNativeModuleType = {
28
28
  model: string;
29
29
  }>;
30
30
  setItem(key: string, value: string): Promise<boolean>;
31
+ onNewToken(fcmPushNotificationToken: string): Promise<boolean>;
32
+ onMessageReceived(): Promise<boolean>;
31
33
  };
32
34
  export declare const OkHiNativeModule: OkHiNativeModuleType;
33
35
  export declare const OkHiNativeEvents: NativeEventEmitter;
@@ -10,9 +10,10 @@ export * from './types';
10
10
  * @param {Object} configuration Configures how verification will start on different platforms
11
11
  * @param {Object} configuration.android Specifices how verification will start on Android platforms
12
12
  * @param {boolean} configuration.android.withForeground Specifices if the foreground service will be turned on to speed up rate of verification, default is true
13
+ * @param {string} fcmPushNotificationToken User's firebase push notification token
13
14
  * @returns {Promise<string>} A promise that resolves to a string value of the location identifier
14
15
  */
15
- export declare const start: (phoneNumber: string, locationId: string, lat: number, lon: number, configuration?: OkVerifyStartConfiguration) => Promise<string>;
16
+ export declare const start: (phoneNumber: string, locationId: string, lat: number, lon: number, configuration?: OkVerifyStartConfiguration, fcmPushNotificationToken?: string) => Promise<string>;
16
17
  /**
17
18
  * Starts verification for a particular address using the response object returned by OkCollect
18
19
  * @param {Object} response Response returned by OkCollect
@@ -58,3 +59,13 @@ export declare const canStartVerification: (configuration?: {
58
59
  * @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
59
60
  */
60
61
  export declare const checkVerificationStartRequirements: () => Promise<boolean>;
62
+ /**
63
+ * Android Only - Updates user's device firebase push notification token
64
+ * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service has started successfully
65
+ */
66
+ export declare const onNewToken: (fcmPushNotificationToken: string) => Promise<boolean>;
67
+ /**
68
+ * Android Only - Should be invoked only when push notification is received.
69
+ * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service has started successfully
70
+ */
71
+ export declare const onMessageReceived: () => Promise<boolean>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-okhi",
3
- "version": "1.1.1-beta.2",
3
+ "version": "1.1.1-beta.4",
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",
@@ -106,7 +106,10 @@ export const OkHiLocationManager = (props: OkHiLocationManagerProps) => {
106
106
  openProtectedAppsSettings();
107
107
  } else {
108
108
  onSuccess({
109
- ...response.payload,
109
+ user: {
110
+ ...response.payload.user,
111
+ fcmPushNotificationToken: user.fcmPushNotificationToken,
112
+ },
110
113
  location: parseOkHiLocation(response.payload.location),
111
114
  startVerification: function (config?: OkVerifyStartConfiguration) {
112
115
  const createdUser = { ...this.user };
@@ -125,7 +128,8 @@ export const OkHiLocationManager = (props: OkHiLocationManagerProps) => {
125
128
  location.id,
126
129
  location.lat,
127
130
  location.lon,
128
- config
131
+ config,
132
+ createdUser.fcmPushNotificationToken
129
133
  )
130
134
  .then(resolve)
131
135
  .catch(reject);
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "okhiWebReactNative",
3
- "version": "1.1.1-beta.1"
3
+ "version": "1.1.1-beta.4"
4
4
  }
@@ -3,6 +3,7 @@ import { OkHiMode } from './OkHiMode';
3
3
  import { OkHiException } from './OkHiException';
4
4
  import type { AuthApplicationConfig, OkHiAccessScope } from './_types';
5
5
  import { getApplicationConfiguration } from './';
6
+ import { OkHiNativeModule } from '../OkHiNativeModule';
6
7
 
7
8
  /**
8
9
  * @ignore
@@ -70,6 +71,10 @@ export class OkHiAuth {
70
71
  const { data } = await axios.post(url, payload, {
71
72
  headers,
72
73
  });
74
+ await OkHiNativeModule.setItem(
75
+ 'okhi:recent:token',
76
+ data.authorization_token
77
+ ); //TODO: move all anonymousSignIn to native code
73
78
  resolve(data.authorization_token);
74
79
  }
75
80
  } catch (error) {
@@ -22,6 +22,11 @@ export interface OkHiUser {
22
22
  * The OkHi's userId. Usually obtained after a user successfully creates an OkHi address.
23
23
  */
24
24
  id?: string;
25
+
26
+ /**
27
+ * The user's device firebase push notification token.
28
+ */
29
+ fcmPushNotificationToken?: string;
25
30
  }
26
31
 
27
32
  /**
@@ -24,7 +24,8 @@ type OkHiNativeModuleType = {
24
24
  locationId: string,
25
25
  lat: Number,
26
26
  lon: Number,
27
- configuration?: OkVerifyStartConfiguration
27
+ configuration?: OkVerifyStartConfiguration,
28
+ fcmPushNotificationToken?: string
28
29
  ): Promise<string>;
29
30
  stopAddressVerification(
30
31
  phoneNumber: string,
@@ -45,6 +46,8 @@ type OkHiNativeModuleType = {
45
46
  openProtectedAppsSettings(): Promise<boolean>;
46
47
  retrieveDeviceInfo(): Promise<{ manufacturer: string; model: string }>;
47
48
  setItem(key: string, value: string): Promise<boolean>;
49
+ onNewToken(fcmPushNotificationToken: string): Promise<boolean>;
50
+ onMessageReceived(): Promise<boolean>;
48
51
  };
49
52
 
50
53
  export const OkHiNativeModule: OkHiNativeModuleType = NativeModules.Okhi
@@ -24,6 +24,7 @@ export * from './types';
24
24
  * @param {Object} configuration Configures how verification will start on different platforms
25
25
  * @param {Object} configuration.android Specifices how verification will start on Android platforms
26
26
  * @param {boolean} configuration.android.withForeground Specifices if the foreground service will be turned on to speed up rate of verification, default is true
27
+ * @param {string} fcmPushNotificationToken User's firebase push notification token
27
28
  * @returns {Promise<string>} A promise that resolves to a string value of the location identifier
28
29
  */
29
30
  export const start = (
@@ -31,7 +32,8 @@ export const start = (
31
32
  locationId: string,
32
33
  lat: number,
33
34
  lon: number,
34
- configuration?: OkVerifyStartConfiguration
35
+ configuration?: OkVerifyStartConfiguration,
36
+ fcmPushNotificationToken?: string
35
37
  ) => {
36
38
  return isValidPlatform(() => {
37
39
  if (Platform.OS === 'android') {
@@ -40,7 +42,8 @@ export const start = (
40
42
  locationId,
41
43
  lat,
42
44
  lon,
43
- configuration
45
+ configuration,
46
+ fcmPushNotificationToken
44
47
  );
45
48
  } else {
46
49
  return OkHiNativeModule.startAddressVerification(
@@ -74,7 +77,8 @@ export const startVerification = async (
74
77
  location.id,
75
78
  location.lat,
76
79
  location.lon,
77
- configuration
80
+ configuration,
81
+ user.fcmPushNotificationToken
78
82
  );
79
83
  resolve(result);
80
84
  } else {
@@ -241,3 +245,26 @@ export const checkVerificationStartRequirements = (): Promise<boolean> => {
241
245
  resolve(true);
242
246
  });
243
247
  };
248
+
249
+ /**
250
+ * Android Only - Updates user's device firebase push notification token
251
+ * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service has started successfully
252
+ */
253
+ export const onNewToken = (fcmPushNotificationToken: string) => {
254
+ return isValidPlatform(
255
+ () =>
256
+ errorHandler(() => OkHiNativeModule.onNewToken(fcmPushNotificationToken)),
257
+ 'android'
258
+ );
259
+ };
260
+
261
+ /**
262
+ * Android Only - Should be invoked only when push notification is received.
263
+ * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service has started successfully
264
+ */
265
+ export const onMessageReceived = () => {
266
+ return isValidPlatform(
267
+ () => errorHandler(OkHiNativeModule.onMessageReceived),
268
+ 'android'
269
+ );
270
+ };