react-native-okhi 1.0.13-beta.1 → 1.0.13-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/.DS_Store +0 -0
- package/android/.idea/workspace.xml +11 -10
- package/android/src/main/java/com/reactnativeokhi/OkhiModule.java +11 -0
- package/ios/.DS_Store +0 -0
- package/ios/Okhi-Bridging-Header.h +1 -0
- package/ios/Okhi.m +4 -1
- package/ios/Okhi.swift +60 -18
- package/ios/Okhi.xcodeproj/project.xcworkspace/xcuserdata/kiano.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/lib/commonjs/OkCollect/OkHiLocationManager.js +22 -5
- package/lib/commonjs/OkCollect/OkHiLocationManager.js.map +1 -1
- package/lib/commonjs/OkCore/Helpers.js +65 -1
- package/lib/commonjs/OkCore/Helpers.js.map +1 -1
- package/lib/commonjs/OkCore/OkHiAuth.js +5 -2
- package/lib/commonjs/OkCore/OkHiAuth.js.map +1 -1
- package/lib/commonjs/OkCore/OkHiException.js +12 -0
- package/lib/commonjs/OkCore/OkHiException.js.map +1 -1
- package/lib/commonjs/OkCore/index.js +2 -2
- package/lib/commonjs/OkCore/index.js.map +1 -1
- package/lib/commonjs/OkHiNativeModule/index.js +4 -1
- package/lib/commonjs/OkHiNativeModule/index.js.map +1 -1
- package/lib/commonjs/OkVerify/index.js +73 -15
- package/lib/commonjs/OkVerify/index.js.map +1 -1
- package/lib/module/OkCollect/OkHiLocationManager.js +22 -5
- package/lib/module/OkCollect/OkHiLocationManager.js.map +1 -1
- package/lib/module/OkCore/Helpers.js +57 -3
- package/lib/module/OkCore/Helpers.js.map +1 -1
- package/lib/module/OkCore/OkHiAuth.js +5 -2
- package/lib/module/OkCore/OkHiAuth.js.map +1 -1
- package/lib/module/OkCore/OkHiException.js +12 -0
- package/lib/module/OkCore/OkHiException.js.map +1 -1
- package/lib/module/OkCore/index.js +2 -2
- package/lib/module/OkCore/index.js.map +1 -1
- package/lib/module/OkHiNativeModule/index.js +3 -1
- package/lib/module/OkHiNativeModule/index.js.map +1 -1
- package/lib/module/OkVerify/index.js +67 -13
- package/lib/module/OkVerify/index.js.map +1 -1
- package/lib/typescript/OkCore/Helpers.d.ts +10 -0
- package/lib/typescript/OkCore/OkHiAuth.d.ts +3 -2
- package/lib/typescript/OkCore/OkHiException.d.ts +8 -0
- package/lib/typescript/OkCore/types.d.ts +3 -0
- package/lib/typescript/OkHiNativeModule/index.d.ts +3 -0
- package/lib/typescript/OkVerify/index.d.ts +5 -0
- package/package.json +1 -1
- package/react-native-okhi.podspec +1 -2
- package/src/OkCollect/OkHiLocationManager.tsx +28 -9
- package/src/OkCore/Helpers.ts +82 -2
- package/src/OkCore/OkHiAuth.ts +6 -3
- package/src/OkCore/OkHiException.ts +9 -0
- package/src/OkCore/index.ts +1 -1
- package/src/OkCore/types.ts +15 -0
- package/src/OkHiNativeModule/index.ts +6 -1
- package/src/OkVerify/index.ts +73 -18
- package/android/.idea/gradle.xml +0 -19
- package/android/.idea/misc.xml +0 -9
- package/android/.idea/modules/android.iml +0 -18
- package/android/.idea/modules.xml +0 -8
- package/android/.idea/vcs.xml +0 -6
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Platform } from 'react-native';
|
|
2
|
-
import { isBackgroundLocationPermissionGranted, isGooglePlayServicesAvailable, isLocationServicesEnabled, requestBackgroundLocationPermission, requestEnableGooglePlayServices, requestEnableLocationServices, requestLocationPermission } from '../OkCore/Helpers';
|
|
2
|
+
import { isBackgroundLocationPermissionGranted, isGooglePlayServicesAvailable, isLocationServicesEnabled, requestBackgroundLocationPermission, requestEnableGooglePlayServices, requestEnableLocationServices, requestLocationPermission, isLocationPermissionGranted } from '../OkCore/Helpers';
|
|
3
3
|
import { errorHandler, isValidPlatform } from '../OkCore/_helpers';
|
|
4
4
|
import { OkHiNativeModule } from '../OkHiNativeModule';
|
|
5
5
|
import { OkHiException } from '../OkCore/OkHiException';
|
|
@@ -104,30 +104,84 @@ export const canStartVerification = configuration => {
|
|
|
104
104
|
const locationServicesStatus = await isLocationServicesEnabled();
|
|
105
105
|
const googlePlayServices = Platform.OS === 'android' ? await isGooglePlayServicesAvailable() : true;
|
|
106
106
|
const backgroundLocationPerm = await isBackgroundLocationPermissionGranted();
|
|
107
|
+
const whenInUseLocationPerm = await isLocationPermissionGranted();
|
|
107
108
|
|
|
108
109
|
if (!requestServices) {
|
|
109
110
|
resolve(locationServicesStatus && googlePlayServices && backgroundLocationPerm);
|
|
110
111
|
return;
|
|
111
112
|
}
|
|
112
113
|
|
|
113
|
-
if (
|
|
114
|
+
if (Platform.OS === 'ios') {
|
|
115
|
+
if (!locationServicesStatus) {
|
|
116
|
+
reject(new OkHiException({
|
|
117
|
+
code: OkHiException.SERVICE_UNAVAILABLE_CODE,
|
|
118
|
+
message: 'Location services is unavailable'
|
|
119
|
+
}));
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (backgroundLocationPerm) {
|
|
124
|
+
resolve(true);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (whenInUseLocationPerm && !backgroundLocationPerm) {
|
|
129
|
+
resolve(false);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const iosPerm = await requestBackgroundLocationPermission();
|
|
134
|
+
resolve(iosPerm);
|
|
135
|
+
return;
|
|
136
|
+
} else if (Platform.OS === 'android') {
|
|
137
|
+
const locationServicesRequestStatus = await requestEnableLocationServices();
|
|
138
|
+
const gPlayServices = await requestEnableGooglePlayServices();
|
|
139
|
+
const androidPerm = (await requestLocationPermission()) && (await requestBackgroundLocationPermission());
|
|
140
|
+
resolve(locationServicesRequestStatus && gPlayServices && androidPerm);
|
|
141
|
+
} else {
|
|
114
142
|
reject(new OkHiException({
|
|
115
|
-
code: OkHiException.
|
|
116
|
-
message:
|
|
143
|
+
code: OkHiException.UNSUPPORTED_PLATFORM_CODE,
|
|
144
|
+
message: OkHiException.UNSUPPORTED_PLATFORM_MESSAGE
|
|
117
145
|
}));
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* Checks whether all necessary permissions and services are available in order to start the address verification process
|
|
151
|
+
* @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
|
|
152
|
+
*/
|
|
122
153
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
154
|
+
export const checkVerificationStartRequirements = () => {
|
|
155
|
+
return new Promise(async (resolve, reject) => {
|
|
156
|
+
if (Platform.OS === 'android') {
|
|
157
|
+
const isPlayServicesAvailable = await isGooglePlayServicesAvailable();
|
|
158
|
+
|
|
159
|
+
if (!isPlayServicesAvailable) {
|
|
160
|
+
reject(new OkHiException({
|
|
161
|
+
code: OkHiException.PLAY_SERVICES_UNAVAILABLE_CODE,
|
|
162
|
+
message: 'Google Play Services is unavailable'
|
|
163
|
+
}));
|
|
164
|
+
return;
|
|
127
165
|
}
|
|
166
|
+
}
|
|
128
167
|
|
|
129
|
-
|
|
168
|
+
if (!(await isLocationServicesEnabled())) {
|
|
169
|
+
reject(new OkHiException({
|
|
170
|
+
code: OkHiException.LOCATION_SERVICES_UNAVAILABLE_CODE,
|
|
171
|
+
message: 'Location services unavailable'
|
|
172
|
+
}));
|
|
173
|
+
return;
|
|
130
174
|
}
|
|
175
|
+
|
|
176
|
+
if (!(await isBackgroundLocationPermissionGranted())) {
|
|
177
|
+
reject(new OkHiException({
|
|
178
|
+
code: OkHiException.PERMISSION_DENIED_CODE,
|
|
179
|
+
message: 'Background Location permission not granted'
|
|
180
|
+
}));
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
resolve(true);
|
|
131
185
|
});
|
|
132
186
|
};
|
|
133
187
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.ts"],"names":["Platform","isBackgroundLocationPermissionGranted","isGooglePlayServicesAvailable","isLocationServicesEnabled","requestBackgroundLocationPermission","requestEnableGooglePlayServices","requestEnableLocationServices","requestLocationPermission","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","SERVICE_UNAVAILABLE_CODE","locationServicesRequestStatus","gPlayServices","perm"],"mappings":"AAAA,SAASA,QAAT,QAAyB,cAAzB;AACA,SACEC,qCADF,EAEEC,6BAFF,EAGEC,yBAHF,EAIEC,mCAJF,EAKEC,+BALF,EAMEC,6BANF,EAOEC,yBAPF,QAQO,mBARP;AASA,SAASC,YAAT,EAAuBC,eAAvB,QAA8C,oBAA9C;AACA,SAASC,gBAAT,QAAiC,qBAAjC;AAGA,SAASC,aAAT,QAA8B,yBAA9B;AACA,cAAc,SAAd;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,KAAK,GAAG,CACnBC,WADmB,EAEnBC,UAFmB,EAGnBC,GAHmB,EAInBC,GAJmB,EAKnBC,aALmB,KAMhB;AACH,SAAOR,eAAe,CAAC,MAAM;AAC3B,QAAIT,QAAQ,CAACkB,EAAT,KAAgB,SAApB,EAA+B;AAC7B,aAAOR,gBAAgB,CAACS,wBAAjB,CACLN,WADK,EAELC,UAFK,EAGLC,GAHK,EAILC,GAJK,EAKLC,aALK,CAAP;AAOD,KARD,MAQO;AACL,aAAOP,gBAAgB,CAACS,wBAAjB,CACLN,WADK,EAELC,UAFK,EAGLC,GAHK,EAILC,GAJK,CAAP;AAMD;AACF,GAjBqB,CAAtB;AAkBD,CAzBM;AA2BP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,QAAQ,CAACkB,EAAT,KAAgB,KAAhB,GACI,IADJ,GAEM,MAAMZ,6BAA6B,EAH3C;AAIA,YAAMuC,aAAa,GACjB7C,QAAQ,CAACkB,EAAT,KAAgB,KAAhB,GAAwB,IAAxB,GAA+B,MAAMb,+BAA+B,EADtE;AAEA,UAAIyC,IAAI,GAAG,KAAX;;AACA,UAAI9C,QAAQ,CAACkB,EAAT,KAAgB,KAApB,EAA2B;AACzB4B,QAAAA,IAAI,GAAG,MAAM1C,mCAAmC,EAAhD;AACD,OAFD,MAEO;AACL0C,QAAAA,IAAI,GACF,CAAC,MAAMvC,yBAAyB,EAAhC,MACC,MAAMH,mCAAmC,EAD1C,CADF;AAGD;;AACDmB,MAAAA,OAAO,CAACqB,6BAA6B,IAAIC,aAAjC,IAAkDC,IAAnD,CAAP;AACD;AACF,GArCM,CAAP;AAsCD,CAzCM","sourcesContent":["import { Platform } from 'react-native';\nimport {\n isBackgroundLocationPermissionGranted,\n isGooglePlayServicesAvailable,\n isLocationServicesEnabled,\n requestBackgroundLocationPermission,\n requestEnableGooglePlayServices,\n requestEnableLocationServices,\n requestLocationPermission,\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 if (!requestServices) {\n resolve(\n locationServicesStatus && googlePlayServices && backgroundLocationPerm\n );\n return;\n }\n if (!locationServicesStatus && Platform.OS === 'ios') {\n reject(\n new OkHiException({\n code: OkHiException.SERVICE_UNAVAILABLE_CODE,\n message: 'Location services is unavailable',\n })\n );\n } else {\n const locationServicesRequestStatus =\n Platform.OS === 'ios'\n ? true\n : ((await requestEnableLocationServices()) as boolean);\n const gPlayServices =\n Platform.OS === 'ios' ? true : await requestEnableGooglePlayServices();\n let perm = false;\n if (Platform.OS === 'ios') {\n perm = await requestBackgroundLocationPermission();\n } else {\n perm =\n (await requestLocationPermission()) &&\n (await requestBackgroundLocationPermission());\n }\n resolve(locationServicesRequestStatus && gPlayServices && perm);\n }\n });\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["index.ts"],"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"],"mappings":"AAAA,SAASA,QAAT,QAAyB,cAAzB;AACA,SACEC,qCADF,EAEEC,6BAFF,EAGEC,yBAHF,EAIEC,mCAJF,EAKEC,+BALF,EAMEC,6BANF,EAOEC,yBAPF,EAQEC,2BARF,QASO,mBATP;AAUA,SAASC,YAAT,EAAuBC,eAAvB,QAA8C,oBAA9C;AACA,SAASC,gBAAT,QAAiC,qBAAjC;AAGA,SAASC,aAAT,QAA8B,yBAA9B;AACA,cAAc,SAAd;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,KAAK,GAAG,CACnBC,WADmB,EAEnBC,UAFmB,EAGnBC,GAHmB,EAInBC,GAJmB,EAKnBC,aALmB,KAMhB;AACH,SAAOR,eAAe,CAAC,MAAM;AAC3B,QAAIV,QAAQ,CAACmB,EAAT,KAAgB,SAApB,EAA+B;AAC7B,aAAOR,gBAAgB,CAACS,wBAAjB,CACLN,WADK,EAELC,UAFK,EAGLC,GAHK,EAILC,GAJK,EAKLC,aAL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AAG,MAAMnD,6BAA6B,EAAnE;;AACA,UAAI,CAACmD,uBAAL,EAA8B;AAC5B5B,QAAAA,MAAM,CACJ,IAAIb,aAAJ,CAAkB;AAChBmB,UAAAA,IAAI,EAAEnB,aAAa,CAAC0C,8BADJ;AAEhBrB,UAAAA,OAAO,EAAE;AAFO,SAAlB,CADI,CAAN;AAMA;AACD;AACF;;AACD,QAAI,EAAE,MAAM9B,yBAAyB,EAAjC,CAAJ,EAA0C;AACxCsB,MAAAA,MAAM,CACJ,IAAIb,aAAJ,CAAkB;AAChBmB,QAAAA,IAAI,EAAEnB,aAAa,CAAC2C,kCADJ;AAEhBtB,QAAAA,OAAO,EAAE;AAFO,OAAlB,CADI,CAAN;AAMA;AACD;;AACD,QAAI,EAAE,MAAMhC,qCAAqC,EAA7C,CAAJ,EAAsD;AACpDwB,MAAAA,MAAM,CACJ,IAAIb,aAAJ,CAAkB;AAChBmB,QAAAA,IAAI,EAAEnB,aAAa,CAAC4C,sBADJ;AAEhBvB,QAAAA,OAAO,EAAE;AAFO,OAAlB,CADI,CAAN;AAMA;AACD;;AACDT,IAAAA,OAAO,CAAC,IAAD,CAAP;AACD,GAhCM,CAAP;AAiCD,CAlCM","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"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { LocationPermissionCallback, LocationPermissionStatus, LocationRequestPermissionType } from './types';
|
|
1
2
|
/**
|
|
2
3
|
* Checks whether location services are enabled
|
|
3
4
|
* @returns {Promise<boolean>} A promise that resolves to a boolen value indicating whether the service is available
|
|
@@ -43,3 +44,12 @@ export declare const requestEnableGooglePlayServices: () => Promise<boolean>;
|
|
|
43
44
|
* @returns {Promise<boolean>} A promise that resolves either a string on iOS or number on Android
|
|
44
45
|
*/
|
|
45
46
|
export declare const getSystemVersion: () => Promise<string | number>;
|
|
47
|
+
export declare const request: (locationPermissionType: LocationRequestPermissionType, rationale: {
|
|
48
|
+
title: string;
|
|
49
|
+
text: string;
|
|
50
|
+
successButton?: {
|
|
51
|
+
label: string;
|
|
52
|
+
};
|
|
53
|
+
} | null, callback: LocationPermissionCallback) => void;
|
|
54
|
+
export declare const openAppSettings: () => void;
|
|
55
|
+
export declare const retriveLocationPermissionStatus: () => Promise<LocationPermissionStatus>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { OkHiAccessScope } from './_types';
|
|
1
|
+
import type { AuthApplicationConfig, OkHiAccessScope } from './_types';
|
|
2
2
|
/**
|
|
3
3
|
* @ignore
|
|
4
4
|
*/
|
|
@@ -8,7 +8,8 @@ export declare class OkHiAuth {
|
|
|
8
8
|
private readonly DEV_BASE_URL;
|
|
9
9
|
private readonly SANDBOX_BASE_URL;
|
|
10
10
|
private readonly PROD_BASE_URL;
|
|
11
|
-
|
|
11
|
+
private config;
|
|
12
|
+
anonymousSignInWithPhoneNumber(phone: string, scopes: Array<OkHiAccessScope>, config: AuthApplicationConfig): Promise<string>;
|
|
12
13
|
protected anonymousSignInWithUserId(userId: string, scopes: Array<OkHiAccessScope>): Promise<string>;
|
|
13
14
|
private anonymousSignIn;
|
|
14
15
|
private parseRequestError;
|
|
@@ -4,6 +4,14 @@ import type { OkHiError } from './types';
|
|
|
4
4
|
* It contains static string properties that can be used to evaluate the kind of errors being thrown and handle them appropriately.
|
|
5
5
|
*/
|
|
6
6
|
export declare class OkHiException extends Error {
|
|
7
|
+
/**
|
|
8
|
+
* Error is thrown when location services is unavailable.
|
|
9
|
+
*/
|
|
10
|
+
static LOCATION_SERVICES_UNAVAILABLE_CODE: string;
|
|
11
|
+
/**
|
|
12
|
+
* Error is thrown when play services is unavailable.
|
|
13
|
+
*/
|
|
14
|
+
static PLAY_SERVICES_UNAVAILABLE_CODE: string;
|
|
7
15
|
/**
|
|
8
16
|
* Error is thrown when the device can't connect to OkHi's servers.
|
|
9
17
|
*/
|
|
@@ -170,3 +170,6 @@ export declare type OkHiApplicationConfiguration = {
|
|
|
170
170
|
channelDescription: string;
|
|
171
171
|
};
|
|
172
172
|
};
|
|
173
|
+
export declare type LocationPermissionStatus = 'notDetermined' | 'restricted' | 'denied' | 'authorizedAlways' | 'authorizedWhenInUse' | 'authorized' | 'unknown';
|
|
174
|
+
export declare type LocationRequestPermissionType = 'whenInUse' | 'always';
|
|
175
|
+
export declare type LocationPermissionCallback = (status: LocationPermissionStatus) => any;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { NativeEventEmitter } from 'react-native';
|
|
1
2
|
import type { OkVerifyStartConfiguration } from '../OkVerify/types';
|
|
2
3
|
declare type OkHiNativeModuleType = {
|
|
3
4
|
multiply(a: number, b: number): Promise<number>;
|
|
@@ -18,6 +19,8 @@ declare type OkHiNativeModuleType = {
|
|
|
18
19
|
stopForegroundService(): Promise<boolean>;
|
|
19
20
|
isForegroundServiceRunning(): Promise<boolean>;
|
|
20
21
|
initializeIOS(branchId: string, clientKey: string, environment: string): Promise<boolean>;
|
|
22
|
+
openAppSettings(): Promise<void>;
|
|
21
23
|
};
|
|
22
24
|
export declare const OkHiNativeModule: OkHiNativeModuleType;
|
|
25
|
+
export declare const OkHiNativeEvents: NativeEventEmitter;
|
|
23
26
|
export {};
|
|
@@ -53,3 +53,8 @@ export declare const isForegroundServiceRunning: () => Promise<boolean>;
|
|
|
53
53
|
export declare const canStartVerification: (configuration?: {
|
|
54
54
|
requestServices?: boolean | undefined;
|
|
55
55
|
} | undefined) => Promise<boolean>;
|
|
56
|
+
/**
|
|
57
|
+
* Checks whether all necessary permissions and services are available in order to start the address verification process
|
|
58
|
+
* @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
|
+
export declare const checkVerificationStartRequirements: () => Promise<boolean>;
|
package/package.json
CHANGED
|
@@ -33,17 +33,36 @@ export const OkHiLocationManager = (props: OkHiLocationManagerProps) => {
|
|
|
33
33
|
const { user, onSuccess, onCloseRequest, onError, loader, launch } = props;
|
|
34
34
|
|
|
35
35
|
useEffect(() => {
|
|
36
|
-
if (user.phone) {
|
|
37
|
-
const auth = new OkHiAuth();
|
|
38
|
-
auth
|
|
39
|
-
.anonymousSignInWithPhoneNumber(user.phone, ['address'])
|
|
40
|
-
.then(setToken)
|
|
41
|
-
.catch(onError);
|
|
36
|
+
if (applicationConfiguration == null && token == null && user.phone) {
|
|
42
37
|
getApplicationConfiguration()
|
|
43
|
-
.then(
|
|
44
|
-
|
|
38
|
+
.then((config) => {
|
|
39
|
+
if (!config && launch) {
|
|
40
|
+
onError(
|
|
41
|
+
new OkHiException({
|
|
42
|
+
code: OkHiException.UNAUTHORIZED_CODE,
|
|
43
|
+
message: OkHiException.UNAUTHORIZED_MESSAGE,
|
|
44
|
+
})
|
|
45
|
+
);
|
|
46
|
+
} else if (config) {
|
|
47
|
+
setApplicationConfiguration(config);
|
|
48
|
+
const auth = new OkHiAuth();
|
|
49
|
+
auth
|
|
50
|
+
.anonymousSignInWithPhoneNumber(user.phone, ['address'], config)
|
|
51
|
+
.then(setToken)
|
|
52
|
+
.catch((error) => {
|
|
53
|
+
if (launch) {
|
|
54
|
+
onError(error);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
.catch((error) => {
|
|
60
|
+
if (launch) {
|
|
61
|
+
onError(error);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
45
64
|
}
|
|
46
|
-
}, [onError, user.phone]);
|
|
65
|
+
}, [onError, user.phone, launch, applicationConfiguration, token]);
|
|
47
66
|
|
|
48
67
|
const handleOnMessage = ({ nativeEvent: { data } }: WebViewMessageEvent) => {
|
|
49
68
|
try {
|
package/src/OkCore/Helpers.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import { OkHiNativeModule } from '../OkHiNativeModule';
|
|
2
|
-
import { PermissionsAndroid, Platform } from 'react-native';
|
|
1
|
+
import { OkHiNativeModule, OkHiNativeEvents } from '../OkHiNativeModule';
|
|
2
|
+
import { Alert, PermissionsAndroid, Platform } from 'react-native';
|
|
3
3
|
import { errorHandler, isValidPlatform } from './_helpers';
|
|
4
|
+
import type {
|
|
5
|
+
LocationPermissionCallback,
|
|
6
|
+
LocationPermissionStatus,
|
|
7
|
+
LocationRequestPermissionType,
|
|
8
|
+
} from './types';
|
|
4
9
|
|
|
5
10
|
/**
|
|
6
11
|
* Checks whether location services are enabled
|
|
@@ -147,3 +152,78 @@ export const requestEnableGooglePlayServices = (): Promise<boolean> => {
|
|
|
147
152
|
*/
|
|
148
153
|
export const getSystemVersion = (): Promise<string | number> =>
|
|
149
154
|
isValidPlatform(OkHiNativeModule.getSystemVersion);
|
|
155
|
+
|
|
156
|
+
export const request = (
|
|
157
|
+
locationPermissionType: LocationRequestPermissionType,
|
|
158
|
+
rationale: {
|
|
159
|
+
title: string;
|
|
160
|
+
text: string;
|
|
161
|
+
successButton?: { label: string };
|
|
162
|
+
} | null,
|
|
163
|
+
callback: LocationPermissionCallback
|
|
164
|
+
) => {
|
|
165
|
+
if (Platform.OS === 'ios') {
|
|
166
|
+
OkHiNativeEvents.removeAllListeners('onLocationPermissionStatusUpdate');
|
|
167
|
+
OkHiNativeEvents.addListener('onLocationPermissionStatusUpdate', callback);
|
|
168
|
+
if (locationPermissionType === 'whenInUse') {
|
|
169
|
+
OkHiNativeModule.requestLocationPermission();
|
|
170
|
+
} else {
|
|
171
|
+
OkHiNativeModule.requestBackgroundLocationPermission();
|
|
172
|
+
}
|
|
173
|
+
} else {
|
|
174
|
+
if (locationPermissionType === 'whenInUse') {
|
|
175
|
+
requestLocationPermissionAndroid().then((result) =>
|
|
176
|
+
callback(result ? 'authorizedWhenInUse' : 'denied')
|
|
177
|
+
);
|
|
178
|
+
} else {
|
|
179
|
+
requestLocationPermissionAndroid().then(async (whenInUseResult) => {
|
|
180
|
+
if (whenInUseResult) {
|
|
181
|
+
const version = await getSystemVersion();
|
|
182
|
+
if (version >= 30 && rationale) {
|
|
183
|
+
Alert.alert(
|
|
184
|
+
rationale.title,
|
|
185
|
+
rationale.text,
|
|
186
|
+
[
|
|
187
|
+
{
|
|
188
|
+
text: rationale.successButton
|
|
189
|
+
? rationale.successButton.label
|
|
190
|
+
: 'Okay',
|
|
191
|
+
onPress: async () => {
|
|
192
|
+
const result = await requestBackgroundLocationPermission();
|
|
193
|
+
callback(
|
|
194
|
+
result ? 'authorizedAlways' : 'authorizedWhenInUse'
|
|
195
|
+
);
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
],
|
|
199
|
+
{
|
|
200
|
+
onDismiss: () => {
|
|
201
|
+
callback('authorizedWhenInUse');
|
|
202
|
+
},
|
|
203
|
+
}
|
|
204
|
+
);
|
|
205
|
+
} else {
|
|
206
|
+
const permission = await requestBackgroundLocationPermission();
|
|
207
|
+
callback(permission ? 'authorizedAlways' : 'authorizedWhenInUse');
|
|
208
|
+
}
|
|
209
|
+
} else {
|
|
210
|
+
callback('denied');
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
export const openAppSettings = () => {
|
|
218
|
+
OkHiNativeModule.openAppSettings();
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
export const retriveLocationPermissionStatus =
|
|
222
|
+
async (): Promise<LocationPermissionStatus> => {
|
|
223
|
+
const alwaysPerm = await isBackgroundLocationPermissionGranted();
|
|
224
|
+
if (alwaysPerm) {
|
|
225
|
+
return 'authorizedAlways';
|
|
226
|
+
}
|
|
227
|
+
const whenInUsePerm = await isLocationPermissionGranted();
|
|
228
|
+
return whenInUsePerm ? 'authorizedWhenInUse' : 'denied';
|
|
229
|
+
};
|
package/src/OkCore/OkHiAuth.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
2
|
import { OkHiMode } from './OkHiMode';
|
|
3
3
|
import { OkHiException } from './OkHiException';
|
|
4
|
-
import type { OkHiAccessScope } from './_types';
|
|
4
|
+
import type { AuthApplicationConfig, OkHiAccessScope } from './_types';
|
|
5
5
|
import { getApplicationConfiguration } from './';
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -18,11 +18,14 @@ export class OkHiAuth {
|
|
|
18
18
|
this.ANONYMOUS_SIGN_IN_ENDPOINT;
|
|
19
19
|
private readonly PROD_BASE_URL =
|
|
20
20
|
`https://api.okhi.io/${this.API_VERSION}` + this.ANONYMOUS_SIGN_IN_ENDPOINT;
|
|
21
|
+
private config: AuthApplicationConfig | null = null;
|
|
21
22
|
|
|
22
23
|
anonymousSignInWithPhoneNumber(
|
|
23
24
|
phone: string,
|
|
24
|
-
scopes: Array<OkHiAccessScope
|
|
25
|
+
scopes: Array<OkHiAccessScope>,
|
|
26
|
+
config: AuthApplicationConfig
|
|
25
27
|
) {
|
|
28
|
+
this.config = config;
|
|
26
29
|
return this.anonymousSignIn({
|
|
27
30
|
scopes,
|
|
28
31
|
phone,
|
|
@@ -45,7 +48,7 @@ export class OkHiAuth {
|
|
|
45
48
|
}): Promise<string> {
|
|
46
49
|
return new Promise(async (resolve, reject) => {
|
|
47
50
|
try {
|
|
48
|
-
const config = await getApplicationConfiguration();
|
|
51
|
+
const config = this.config || (await getApplicationConfiguration());
|
|
49
52
|
if (config === null || !config.auth || !config.auth.token) {
|
|
50
53
|
reject(
|
|
51
54
|
new OkHiException({
|
|
@@ -5,6 +5,15 @@ import type { OkHiError } from './types';
|
|
|
5
5
|
* It contains static string properties that can be used to evaluate the kind of errors being thrown and handle them appropriately.
|
|
6
6
|
*/
|
|
7
7
|
export class OkHiException extends Error {
|
|
8
|
+
/**
|
|
9
|
+
* Error is thrown when location services is unavailable.
|
|
10
|
+
*/
|
|
11
|
+
static LOCATION_SERVICES_UNAVAILABLE_CODE = 'location_services_unavailable';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Error is thrown when play services is unavailable.
|
|
15
|
+
*/
|
|
16
|
+
static PLAY_SERVICES_UNAVAILABLE_CODE = 'play_services_unavailable';
|
|
8
17
|
/**
|
|
9
18
|
* Error is thrown when the device can't connect to OkHi's servers.
|
|
10
19
|
*/
|
package/src/OkCore/index.ts
CHANGED
|
@@ -20,6 +20,7 @@ export function initialize(
|
|
|
20
20
|
configuration: OkHiApplicationConfiguration
|
|
21
21
|
): Promise<void> {
|
|
22
22
|
return errorHandler(async () => {
|
|
23
|
+
okhiApplicationConfiguration = configuration;
|
|
23
24
|
if (Platform.OS === 'android') {
|
|
24
25
|
await OkHiNativeModule.initialize(JSON.stringify(configuration));
|
|
25
26
|
} else {
|
|
@@ -29,7 +30,6 @@ export function initialize(
|
|
|
29
30
|
configuration.context.mode
|
|
30
31
|
);
|
|
31
32
|
}
|
|
32
|
-
okhiApplicationConfiguration = configuration;
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
35
|
|
package/src/OkCore/types.ts
CHANGED
|
@@ -178,3 +178,18 @@ export type OkHiApplicationConfiguration = {
|
|
|
178
178
|
channelDescription: string;
|
|
179
179
|
};
|
|
180
180
|
};
|
|
181
|
+
|
|
182
|
+
export type LocationPermissionStatus =
|
|
183
|
+
| 'notDetermined'
|
|
184
|
+
| 'restricted'
|
|
185
|
+
| 'denied'
|
|
186
|
+
| 'authorizedAlways'
|
|
187
|
+
| 'authorizedWhenInUse'
|
|
188
|
+
| 'authorized'
|
|
189
|
+
| 'unknown';
|
|
190
|
+
|
|
191
|
+
export type LocationRequestPermissionType = 'whenInUse' | 'always';
|
|
192
|
+
|
|
193
|
+
export type LocationPermissionCallback = (
|
|
194
|
+
status: LocationPermissionStatus
|
|
195
|
+
) => any;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NativeModules } from 'react-native';
|
|
1
|
+
import { NativeModules, NativeEventEmitter } from 'react-native';
|
|
2
2
|
import type { OkVerifyStartConfiguration } from '../OkVerify/types';
|
|
3
3
|
|
|
4
4
|
type OkHiNativeModuleType = {
|
|
@@ -33,6 +33,11 @@ type OkHiNativeModuleType = {
|
|
|
33
33
|
clientKey: string,
|
|
34
34
|
environment: string
|
|
35
35
|
): Promise<boolean>;
|
|
36
|
+
openAppSettings(): Promise<void>;
|
|
36
37
|
};
|
|
37
38
|
|
|
38
39
|
export const OkHiNativeModule: OkHiNativeModuleType = NativeModules.Okhi;
|
|
40
|
+
|
|
41
|
+
export const OkHiNativeEvents = new NativeEventEmitter(NativeModules.Okhi);
|
|
42
|
+
|
|
43
|
+
OkHiNativeEvents.addListener('onLocationPermissionStatusUpdate', () => null);
|
package/src/OkVerify/index.ts
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
requestEnableGooglePlayServices,
|
|
8
8
|
requestEnableLocationServices,
|
|
9
9
|
requestLocationPermission,
|
|
10
|
+
isLocationPermissionGranted,
|
|
10
11
|
} from '../OkCore/Helpers';
|
|
11
12
|
import { errorHandler, isValidPlatform } from '../OkCore/_helpers';
|
|
12
13
|
import { OkHiNativeModule } from '../OkHiNativeModule';
|
|
@@ -154,35 +155,89 @@ export const canStartVerification = (configuration?: {
|
|
|
154
155
|
Platform.OS === 'android' ? await isGooglePlayServicesAvailable() : true;
|
|
155
156
|
const backgroundLocationPerm =
|
|
156
157
|
await isBackgroundLocationPermissionGranted();
|
|
158
|
+
const whenInUseLocationPerm = await isLocationPermissionGranted();
|
|
157
159
|
if (!requestServices) {
|
|
158
160
|
resolve(
|
|
159
161
|
locationServicesStatus && googlePlayServices && backgroundLocationPerm
|
|
160
162
|
);
|
|
161
163
|
return;
|
|
162
164
|
}
|
|
163
|
-
if (
|
|
165
|
+
if (Platform.OS === 'ios') {
|
|
166
|
+
if (!locationServicesStatus) {
|
|
167
|
+
reject(
|
|
168
|
+
new OkHiException({
|
|
169
|
+
code: OkHiException.SERVICE_UNAVAILABLE_CODE,
|
|
170
|
+
message: 'Location services is unavailable',
|
|
171
|
+
})
|
|
172
|
+
);
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
if (backgroundLocationPerm) {
|
|
176
|
+
resolve(true);
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
if (whenInUseLocationPerm && !backgroundLocationPerm) {
|
|
180
|
+
resolve(false);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
const iosPerm = await requestBackgroundLocationPermission();
|
|
184
|
+
resolve(iosPerm);
|
|
185
|
+
return;
|
|
186
|
+
} else if (Platform.OS === 'android') {
|
|
187
|
+
const locationServicesRequestStatus =
|
|
188
|
+
(await requestEnableLocationServices()) as boolean;
|
|
189
|
+
const gPlayServices = await requestEnableGooglePlayServices();
|
|
190
|
+
const androidPerm =
|
|
191
|
+
(await requestLocationPermission()) &&
|
|
192
|
+
(await requestBackgroundLocationPermission());
|
|
193
|
+
resolve(locationServicesRequestStatus && gPlayServices && androidPerm);
|
|
194
|
+
} else {
|
|
164
195
|
reject(
|
|
165
196
|
new OkHiException({
|
|
166
|
-
code: OkHiException.
|
|
167
|
-
message:
|
|
197
|
+
code: OkHiException.UNSUPPORTED_PLATFORM_CODE,
|
|
198
|
+
message: OkHiException.UNSUPPORTED_PLATFORM_MESSAGE,
|
|
168
199
|
})
|
|
169
200
|
);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Checks whether all necessary permissions and services are available in order to start the address verification process
|
|
207
|
+
* @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
|
|
208
|
+
*/
|
|
209
|
+
export const checkVerificationStartRequirements = (): Promise<boolean> => {
|
|
210
|
+
return new Promise(async (resolve, reject) => {
|
|
211
|
+
if (Platform.OS === 'android') {
|
|
212
|
+
const isPlayServicesAvailable = await isGooglePlayServicesAvailable();
|
|
213
|
+
if (!isPlayServicesAvailable) {
|
|
214
|
+
reject(
|
|
215
|
+
new OkHiException({
|
|
216
|
+
code: OkHiException.PLAY_SERVICES_UNAVAILABLE_CODE,
|
|
217
|
+
message: 'Google Play Services is unavailable',
|
|
218
|
+
})
|
|
219
|
+
);
|
|
220
|
+
return;
|
|
184
221
|
}
|
|
185
|
-
resolve(locationServicesRequestStatus && gPlayServices && perm);
|
|
186
222
|
}
|
|
223
|
+
if (!(await isLocationServicesEnabled())) {
|
|
224
|
+
reject(
|
|
225
|
+
new OkHiException({
|
|
226
|
+
code: OkHiException.LOCATION_SERVICES_UNAVAILABLE_CODE,
|
|
227
|
+
message: 'Location services unavailable',
|
|
228
|
+
})
|
|
229
|
+
);
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
if (!(await isBackgroundLocationPermissionGranted())) {
|
|
233
|
+
reject(
|
|
234
|
+
new OkHiException({
|
|
235
|
+
code: OkHiException.PERMISSION_DENIED_CODE,
|
|
236
|
+
message: 'Background Location permission not granted',
|
|
237
|
+
})
|
|
238
|
+
);
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
resolve(true);
|
|
187
242
|
});
|
|
188
243
|
};
|
package/android/.idea/gradle.xml
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<project version="4">
|
|
3
|
-
<component name="GradleSettings">
|
|
4
|
-
<option name="linkedExternalProjectsSettings">
|
|
5
|
-
<GradleProjectSettings>
|
|
6
|
-
<option name="testRunner" value="GRADLE" />
|
|
7
|
-
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
|
8
|
-
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
|
9
|
-
<option name="gradleHome" value="/usr/local/Cellar/gradle/6.6.1/libexec" />
|
|
10
|
-
<option name="modules">
|
|
11
|
-
<set>
|
|
12
|
-
<option value="$PROJECT_DIR$" />
|
|
13
|
-
</set>
|
|
14
|
-
</option>
|
|
15
|
-
<option name="resolveModulePerSourceSet" value="false" />
|
|
16
|
-
</GradleProjectSettings>
|
|
17
|
-
</option>
|
|
18
|
-
</component>
|
|
19
|
-
</project>
|