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 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.ts"],"names":["OkHiNativeModule","NativeModules","Okhi"],"mappings":";;;;;;;AAAA;;
|
|
1
|
+
{"version":3,"sources":["index.ts"],"names":["OkHiNativeModule","NativeModules","Okhi","OkHiNativeEvents","NativeEventEmitter","addListener"],"mappings":";;;;;;;AAAA;;AAsCO,MAAMA,gBAAsC,GAAGC,2BAAcC,IAA7D;;AAEA,MAAMC,gBAAgB,GAAG,IAAIC,+BAAJ,CAAuBH,2BAAcC,IAArC,CAAzB;;AAEPC,gBAAgB,CAACE,WAAjB,CAA6B,kCAA7B,EAAiE,MAAM,IAAvE","sourcesContent":["import { NativeModules, NativeEventEmitter } from 'react-native';\nimport type { OkVerifyStartConfiguration } from '../OkVerify/types';\n\ntype OkHiNativeModuleType = {\n multiply(a: number, b: number): Promise<number>;\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};\n\nexport const OkHiNativeModule: OkHiNativeModuleType = NativeModules.Okhi;\n\nexport const OkHiNativeEvents = new NativeEventEmitter(NativeModules.Okhi);\n\nOkHiNativeEvents.addListener('onLocationPermissionStatusUpdate', () => null);\n"]}
|
|
@@ -10,9 +10,10 @@ var _exportNames = {
|
|
|
10
10
|
startForegroundService: true,
|
|
11
11
|
stopForegroundService: true,
|
|
12
12
|
isForegroundServiceRunning: true,
|
|
13
|
-
canStartVerification: true
|
|
13
|
+
canStartVerification: true,
|
|
14
|
+
checkVerificationStartRequirements: true
|
|
14
15
|
};
|
|
15
|
-
exports.stopVerification = exports.stopForegroundService = exports.startVerification = exports.startForegroundService = exports.start = exports.isForegroundServiceRunning = exports.canStartVerification = void 0;
|
|
16
|
+
exports.stopVerification = exports.stopForegroundService = exports.startVerification = exports.startForegroundService = exports.start = exports.isForegroundServiceRunning = exports.checkVerificationStartRequirements = exports.canStartVerification = void 0;
|
|
16
17
|
|
|
17
18
|
var _reactNative = require("react-native");
|
|
18
19
|
|
|
@@ -157,32 +158,89 @@ const canStartVerification = configuration => {
|
|
|
157
158
|
const locationServicesStatus = await (0, _Helpers.isLocationServicesEnabled)();
|
|
158
159
|
const googlePlayServices = _reactNative.Platform.OS === 'android' ? await (0, _Helpers.isGooglePlayServicesAvailable)() : true;
|
|
159
160
|
const backgroundLocationPerm = await (0, _Helpers.isBackgroundLocationPermissionGranted)();
|
|
161
|
+
const whenInUseLocationPerm = await (0, _Helpers.isLocationPermissionGranted)();
|
|
160
162
|
|
|
161
163
|
if (!requestServices) {
|
|
162
164
|
resolve(locationServicesStatus && googlePlayServices && backgroundLocationPerm);
|
|
163
165
|
return;
|
|
164
166
|
}
|
|
165
167
|
|
|
166
|
-
if (
|
|
168
|
+
if (_reactNative.Platform.OS === 'ios') {
|
|
169
|
+
if (!locationServicesStatus) {
|
|
170
|
+
reject(new _OkHiException.OkHiException({
|
|
171
|
+
code: _OkHiException.OkHiException.SERVICE_UNAVAILABLE_CODE,
|
|
172
|
+
message: 'Location services is unavailable'
|
|
173
|
+
}));
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (backgroundLocationPerm) {
|
|
178
|
+
resolve(true);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (whenInUseLocationPerm && !backgroundLocationPerm) {
|
|
183
|
+
resolve(false);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const iosPerm = await (0, _Helpers.requestBackgroundLocationPermission)();
|
|
188
|
+
resolve(iosPerm);
|
|
189
|
+
return;
|
|
190
|
+
} else if (_reactNative.Platform.OS === 'android') {
|
|
191
|
+
const locationServicesRequestStatus = await (0, _Helpers.requestEnableLocationServices)();
|
|
192
|
+
const gPlayServices = await (0, _Helpers.requestEnableGooglePlayServices)();
|
|
193
|
+
const androidPerm = (await (0, _Helpers.requestLocationPermission)()) && (await (0, _Helpers.requestBackgroundLocationPermission)());
|
|
194
|
+
resolve(locationServicesRequestStatus && gPlayServices && androidPerm);
|
|
195
|
+
} else {
|
|
167
196
|
reject(new _OkHiException.OkHiException({
|
|
168
|
-
code: _OkHiException.OkHiException.
|
|
169
|
-
message:
|
|
197
|
+
code: _OkHiException.OkHiException.UNSUPPORTED_PLATFORM_CODE,
|
|
198
|
+
message: _OkHiException.OkHiException.UNSUPPORTED_PLATFORM_MESSAGE
|
|
170
199
|
}));
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
};
|
|
203
|
+
/**
|
|
204
|
+
* Checks whether all necessary permissions and services are available in order to start the address verification process
|
|
205
|
+
* @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
|
|
206
|
+
*/
|
|
175
207
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
208
|
+
|
|
209
|
+
exports.canStartVerification = canStartVerification;
|
|
210
|
+
|
|
211
|
+
const checkVerificationStartRequirements = () => {
|
|
212
|
+
return new Promise(async (resolve, reject) => {
|
|
213
|
+
if (_reactNative.Platform.OS === 'android') {
|
|
214
|
+
const isPlayServicesAvailable = await (0, _Helpers.isGooglePlayServicesAvailable)();
|
|
215
|
+
|
|
216
|
+
if (!isPlayServicesAvailable) {
|
|
217
|
+
reject(new _OkHiException.OkHiException({
|
|
218
|
+
code: _OkHiException.OkHiException.PLAY_SERVICES_UNAVAILABLE_CODE,
|
|
219
|
+
message: 'Google Play Services is unavailable'
|
|
220
|
+
}));
|
|
221
|
+
return;
|
|
180
222
|
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (!(await (0, _Helpers.isLocationServicesEnabled)())) {
|
|
226
|
+
reject(new _OkHiException.OkHiException({
|
|
227
|
+
code: _OkHiException.OkHiException.LOCATION_SERVICES_UNAVAILABLE_CODE,
|
|
228
|
+
message: 'Location services unavailable'
|
|
229
|
+
}));
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
181
232
|
|
|
182
|
-
|
|
233
|
+
if (!(await (0, _Helpers.isBackgroundLocationPermissionGranted)())) {
|
|
234
|
+
reject(new _OkHiException.OkHiException({
|
|
235
|
+
code: _OkHiException.OkHiException.PERMISSION_DENIED_CODE,
|
|
236
|
+
message: 'Background Location permission not granted'
|
|
237
|
+
}));
|
|
238
|
+
return;
|
|
183
239
|
}
|
|
240
|
+
|
|
241
|
+
resolve(true);
|
|
184
242
|
});
|
|
185
243
|
};
|
|
186
244
|
|
|
187
|
-
exports.
|
|
245
|
+
exports.checkVerificationStartRequirements = checkVerificationStartRequirements;
|
|
188
246
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.ts"],"names":["start","phoneNumber","locationId","lat","lon","configuration","Platform","OS","OkHiNativeModule","startAddressVerification","startVerification","response","Promise","resolve","reject","location","user","id","result","phone","OkHiException","code","BAD_REQUEST_CODE","message","stopVerification","stopAddressVerification","startForegroundService","stopForegroundService","isForegroundServiceRunning","canStartVerification","requestServices","locationServicesStatus","googlePlayServices","backgroundLocationPerm","SERVICE_UNAVAILABLE_CODE","locationServicesRequestStatus","gPlayServices","perm"],"mappings":";;;;;;;;;;;;;;;;AAAA;;AACA;;AASA;;AACA;;AAGA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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;AACH,SAAO,8BAAgB,MAAM;AAC3B,QAAIC,sBAASC,EAAT,KAAgB,SAApB,EAA+B;AAC7B,aAAOC,mCAAiBC,wBAAjB,CACLR,WADK,EAELC,UAFK,EAGLC,GAHK,EAILC,GAJK,EAKL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ACjC7B,sBAASC,EAAT,KAAgB,KAAhB,GACI,IADJ,GAEM,MAAM,6CAHd;AAIA,YAAM6B,aAAa,GACjB9B,sBAASC,EAAT,KAAgB,KAAhB,GAAwB,IAAxB,GAA+B,MAAM,+CADvC;AAEA,UAAI8B,IAAI,GAAG,KAAX;;AACA,UAAI/B,sBAASC,EAAT,KAAgB,KAApB,EAA2B;AACzB8B,QAAAA,IAAI,GAAG,MAAM,mDAAb;AACD,OAFD,MAEO;AACLA,QAAAA,IAAI,GACF,CAAC,MAAM,yCAAP,MACC,MAAM,mDADP,CADF;AAGD;;AACDxB,MAAAA,OAAO,CAACsB,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":["start","phoneNumber","locationId","lat","lon","configuration","Platform","OS","OkHiNativeModule","startAddressVerification","startVerification","response","Promise","resolve","reject","location","user","id","result","phone","OkHiException","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;;AACA;;AAUA;;AACA;;AAGA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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;AACH,SAAO,8BAAgB,MAAM;AAC3B,QAAIC,sBAASC,EAAT,KAAgB,SAApB,EAA+B;AAC7B,aAAOC,mCAAiBC,wBAAjB,CACLR,WADK,EAELC,UAFK,EAGLC,GAHK,EAILC,GAJK,EAKLC,aALK,CAAP;AAOD,KARD,MAQO;AACL,aAAOG,mCAAiBC,wBAAjB,CACLR,WADK,EAELC,UAFK,EAGLC,GAHK,EAILC,GAJK,CAAP;AAMD;AACF,GAjBM,CAAP;AAkBD,CAzBM;AA2BP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AACO,MAAMM,iBAAiB,GAAG,OAC/BC,QAD+B,EAE/BN,aAF+B,KAG5B;AACH,SAAO,IAAIO,OAAJ,CAAY,CAACC,OAAD,EAAUC,MAAV,KAAqB;AACtC,UAAM;AAAEC,MAAAA,QAAF;AAAYC,MAAAA;AAAZ,QAAqBL,QAA3B;;AACA,Q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AAP;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"]}
|
|
@@ -29,12 +29,29 @@ export const OkHiLocationManager = props => {
|
|
|
29
29
|
launch
|
|
30
30
|
} = props;
|
|
31
31
|
useEffect(() => {
|
|
32
|
-
if (user.phone) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
if (applicationConfiguration == null && token == null && user.phone) {
|
|
33
|
+
getApplicationConfiguration().then(config => {
|
|
34
|
+
if (!config && launch) {
|
|
35
|
+
onError(new OkHiException({
|
|
36
|
+
code: OkHiException.UNAUTHORIZED_CODE,
|
|
37
|
+
message: OkHiException.UNAUTHORIZED_MESSAGE
|
|
38
|
+
}));
|
|
39
|
+
} else if (config) {
|
|
40
|
+
setApplicationConfiguration(config);
|
|
41
|
+
const auth = new OkHiAuth();
|
|
42
|
+
auth.anonymousSignInWithPhoneNumber(user.phone, ['address'], config).then(setToken).catch(error => {
|
|
43
|
+
if (launch) {
|
|
44
|
+
onError(error);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}).catch(error => {
|
|
49
|
+
if (launch) {
|
|
50
|
+
onError(error);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
36
53
|
}
|
|
37
|
-
}, [onError, user.phone]);
|
|
54
|
+
}, [onError, user.phone, launch, applicationConfiguration, token]);
|
|
38
55
|
|
|
39
56
|
const handleOnMessage = _ref => {
|
|
40
57
|
let {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["OkHiLocationManager.tsx"],"names":["React","useState","useEffect","Modal","SafeAreaView","Platform","WebView","Spinner","getFrameUrl","generateJavaScriptStartScript","generateStartDataPayload","parseOkHiLocation","OkHiException","OkHiAuth","start","sv","getApplicationConfiguration","OkHiLocationManager","props","token","setToken","applicationConfiguration","setApplicationConfiguration","defaultStyle","flex","style","user","onSuccess","onCloseRequest","onError","loader","launch","phone","auth","anonymousSignInWithPhoneNumber","then","catch","handleOnMessage","nativeEvent","data","response","JSON","parse","message","code","UNKNOWN_ERROR_CODE","payload","toString","location","startVerification","config","createdUser","Promise","resolve","reject","id","BAD_REQUEST_CODE","lat","lon","error","errorMessage","Error","handleOnError","NETWORK_ERROR_CODE","NETWORK_ERROR_MESSAGE","renderContent","jsAfterLoad","jsBeforeLoad","uri","OS","undefined"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,QAAhB,EAA0BC,SAA1B,QAA2C,OAA3C;AACA,SAASC,KAAT,EAAgBC,YAAhB,EAA8BC,QAA9B,QAA8C,cAA9C;AACA,SAASC,OAAT,QAA6C,sBAA7C;AACA,SAASC,OAAT,QAAwB,WAAxB;AAKA,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,SAASC,2BAAT,QAA4C,WAA5C;AACA;AACA;AACA;;AACA,OAAO,MAAMC,mBAAmB,GAAIC,KAAD,IAAqC;AACtE,QAAM,CAACC,KAAD,EAAQC,QAAR,IAAoBnB,QAAQ,CAAgB,IAAhB,CAAlC;AACA,QAAM,CAACoB,wBAAD,EAA2BC,2BAA3B,IACJrB,QAAQ,CAA+B,IAA/B,CADV;AAEA,QAAMsB,YAAY,GAAG;AAAEC,IAAAA,IAAI,EAAE;AAAR,GAArB;AACA,QAAMC,KAAK,GAAGP,KAAK,CAACO,KAAN,GACV,EAAE,GAAGP,KAAK,CAACO,KAAX;AAAkB,OAAGF;AAArB,GADU,GAEVA,YAFJ;AA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AlB,CADK,CAAP;AAMD,GAPD;;AASA,QAAMC,aAAa,GAAG,MAAM;AAC1B,QAAI9C,KAAK,KAAK,IAAV,IAAkBE,wBAAwB,IAAI,IAAlD,EAAwD;AACtD,aAAOS,MAAM,iBAAI,oBAAC,OAAD,OAAjB;AACD;;AAED,UAAM;AAAEoC,MAAAA,WAAF;AAAeC,MAAAA;AAAf,QAAgC1D,6BAA6B,CAAC;AAClEkC,MAAAA,OAAO,EAAE,iBADyD;AAElEG,MAAAA,OAAO,EAAEpC,wBAAwB,CAACQ,KAAD,EAAQC,KAAR,EAAeE,wBAAf;AAFiC,KAAD,CAAnE;AAKA,wBACE,oBAAC,YAAD;AAAc,MAAA,KAAK,EAAEI;AAArB,oBACE,oBAAC,OAAD;AACE,MAAA,MAAM,EAAE;AAAE2C,QAAAA,GAAG,EAAE5D,WAAW,CAACa,wBAAD;AAAlB,OADV;AAEE,MAAA,qCAAqC,EACnChB,QAAQ,CAACgE,EAAT,KAAgB,KAAhB,GAAwBF,YAAxB,GAAuCG,SAH3C;AAKE,MAAA,kBAAkB,EAAEjE,QAAQ,CAACgE,EAAT,KAAgB,KAAhB,GAAwBC,SAAxB,GAAoCJ,WAL1D;AAME,MAAA,SAAS,EAAE7B,eANb;AAOE,MAAA,OAAO,EAAEyB,aAPX;AAQE,MAAA,WAAW,EAAEA,aARf;AASE,MAAA,kBAAkB,EAAE,IATtB;AAUE,MAAA,mCAAmC,EAAE;AAVvC,MADF,CADF;AAgBD,GA1BD;;AA4BA,sBACE,oBAAC,KAAD;AAAO,IAAA,aAAa,EAAC,OAArB;AAA6B,IAAA,WAAW,EAAE,KAA1C;AAAiD,IAAA,OAAO,EAAE/B;AAA1D,KACGA,MAAM,GAAGkC,aAAa,EAAhB,GAAqB,IAD9B,CADF;AAKD,CA1HM;AA4HP,eAAehD,mBAAf","sourcesContent":["import React, { useState, useEffect } 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} 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 { getApplicationConfiguration } from '../OkCore';\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 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\n useEffect(() => {\n if (user.phone) {\n const auth = new OkHiAuth();\n auth\n .anonymousSignInWithPhoneNumber(user.phone, ['address'])\n .then(setToken)\n .catch(onError);\n getApplicationConfiguration()\n .then(setApplicationConfiguration)\n .catch(onError);\n }\n }, [onError, user.phone]);\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 {\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 renderContent = () => {\n if (token === null || applicationConfiguration == null) {\n return loader || <Spinner />;\n }\n\n const { jsAfterLoad, jsBeforeLoad } = generateJavaScriptStartScript({\n message: 'select_location',\n payload: generateStartDataPayload(props, token, applicationConfiguration),\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 />\n </SafeAreaView>\n );\n };\n\n return (\n <Modal animationType=\"slide\" transparent={false} visible={launch}>\n {launch ? renderContent() : null}\n </Modal>\n );\n};\n\nexport default OkHiLocationManager;\n"]}
|
|
1
|
+
{"version":3,"sources":["OkHiLocationManager.tsx"],"names":["React","useState","useEffect","Modal","SafeAreaView","Platform","WebView","Spinner","getFrameUrl","generateJavaScriptStartScript","generateStartDataPayload","parseOkHiLocation","OkHiException","OkHiAuth","start","sv","getApplicationConfiguration","OkHiLocationManager","props","token","setToken","applicationConfiguration","setApplicationConfiguration","defaultStyle","flex","style","user","onSuccess","onCloseRequest","onError","loader","launch","phone","then","config","code","UNAUTHORIZED_CODE","message","UNAUTHORIZED_MESSAGE","auth","anonymousSignInWithPhoneNumber","catch","error","handleOnMessage","nativeEvent","data","response","JSON","parse","UNKNOWN_ERROR_CODE","payload","toString","location","startVerification","createdUser","Promise","resolve","reject","id","BAD_REQUEST_CODE","lat","lon","errorMessage","Error","handleOnError","NETWORK_ERROR_CODE","NETWORK_ERROR_MESSAGE","renderContent","jsAfterLoad","jsBeforeLoad","uri","OS","undefined"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,QAAhB,EAA0BC,SAA1B,QAA2C,OAA3C;AACA,SAASC,KAAT,EAAgBC,YAAhB,EAA8BC,QAA9B,QAA8C,cAA9C;AACA,SAASC,OAAT,QAA6C,sBAA7C;AACA,SAASC,OAAT,QAAwB,WAAxB;AAKA,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,SAASC,2BAAT,QAA4C,WAA5C;AACA;AACA;AACA;;AACA,OAAO,MAAMC,mBAAmB,GAAIC,KAAD,IAAqC;AACtE,QAAM,CAACC,KAAD,EAAQC,QAAR,IAAoBnB,QAAQ,CAAgB,IAAhB,CAAlC;AACA,QAAM,CAACoB,wBAAD,EAA2BC,2BAA3B,IACJrB,QAAQ,CAA+B,IAA/B,CADV;AAEA,QAAMsB,YAAY,GAAG;AAAEC,IAAAA,IAAI,EAAE;AAAR,GAArB;AACA,QAAMC,KAAK,GAAGP,KAAK,CAACO,KAAN,GACV,EAAE,GAAGP,KAAK,CAACO,KAAX;AAAkB,OAAGF;AAArB,GADU,GAEVA,YAFJ;AAIA,QAAM;AAAEG,IAAAA,IAAF;AAAQC,IAAAA,SAAR;AAAmBC,IAAAA,cAAnB;AAAmCC,IAAAA,OAAnC;AAA4CC,IAAAA,MAA5C;AAAoDC,IAAAA;AAApD,MAA+Db,KAArE;AAEAhB,EAAAA,SAAS,CAAC,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E,MAAA,OAAO,EAAEqB,aAPX;AAQE,MAAA,WAAW,EAAEA,aARf;AASE,MAAA,kBAAkB,EAAE,IATtB;AAUE,MAAA,mCAAmC,EAAE;AAVvC,MADF,CADF;AAgBD,GA1BD;;AA4BA,sBACE,oBAAC,KAAD;AAAO,IAAA,aAAa,EAAC,OAArB;AAA6B,IAAA,WAAW,EAAE,KAA1C;AAAiD,IAAA,OAAO,EAAEjC;AAA1D,KACGA,MAAM,GAAGoC,aAAa,EAAhB,GAAqB,IAD9B,CADF;AAKD,CA7IM;AA+IP,eAAelD,mBAAf","sourcesContent":["import React, { useState, useEffect } 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} 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 { getApplicationConfiguration } from '../OkCore';\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 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\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, ['address'], config)\n .then(setToken)\n .catch((error) => {\n if (launch) {\n onError(error);\n }\n });\n }\n })\n .catch((error) => {\n if (launch) {\n onError(error);\n }\n });\n }\n }, [onError, user.phone, launch, applicationConfiguration, 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 {\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 renderContent = () => {\n if (token === null || applicationConfiguration == null) {\n return loader || <Spinner />;\n }\n\n const { jsAfterLoad, jsBeforeLoad } = generateJavaScriptStartScript({\n message: 'select_location',\n payload: generateStartDataPayload(props, token, applicationConfiguration),\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 />\n </SafeAreaView>\n );\n };\n\n return (\n <Modal animationType=\"slide\" transparent={false} visible={launch}>\n {launch ? renderContent() : null}\n </Modal>\n );\n};\n\nexport default OkHiLocationManager;\n"]}
|
|
@@ -1,11 +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
|
+
|
|
4
5
|
/**
|
|
5
6
|
* Checks whether location services are enabled
|
|
6
7
|
* @returns {Promise<boolean>} A promise that resolves to a boolen value indicating whether the service is available
|
|
7
8
|
*/
|
|
8
|
-
|
|
9
9
|
export const isLocationServicesEnabled = () => {
|
|
10
10
|
return isValidPlatform(OkHiNativeModule.isLocationServicesEnabled);
|
|
11
11
|
};
|
|
@@ -124,4 +124,58 @@ export const requestEnableGooglePlayServices = () => {
|
|
|
124
124
|
*/
|
|
125
125
|
|
|
126
126
|
export const getSystemVersion = () => isValidPlatform(OkHiNativeModule.getSystemVersion);
|
|
127
|
+
export const request = (locationPermissionType, rationale, callback) => {
|
|
128
|
+
if (Platform.OS === 'ios') {
|
|
129
|
+
OkHiNativeEvents.removeAllListeners('onLocationPermissionStatusUpdate');
|
|
130
|
+
OkHiNativeEvents.addListener('onLocationPermissionStatusUpdate', callback);
|
|
131
|
+
|
|
132
|
+
if (locationPermissionType === 'whenInUse') {
|
|
133
|
+
OkHiNativeModule.requestLocationPermission();
|
|
134
|
+
} else {
|
|
135
|
+
OkHiNativeModule.requestBackgroundLocationPermission();
|
|
136
|
+
}
|
|
137
|
+
} else {
|
|
138
|
+
if (locationPermissionType === 'whenInUse') {
|
|
139
|
+
requestLocationPermissionAndroid().then(result => callback(result ? 'authorizedWhenInUse' : 'denied'));
|
|
140
|
+
} else {
|
|
141
|
+
requestLocationPermissionAndroid().then(async whenInUseResult => {
|
|
142
|
+
if (whenInUseResult) {
|
|
143
|
+
const version = await getSystemVersion();
|
|
144
|
+
|
|
145
|
+
if (version >= 30 && rationale) {
|
|
146
|
+
Alert.alert(rationale.title, rationale.text, [{
|
|
147
|
+
text: rationale.successButton ? rationale.successButton.label : 'Okay',
|
|
148
|
+
onPress: async () => {
|
|
149
|
+
const result = await requestBackgroundLocationPermission();
|
|
150
|
+
callback(result ? 'authorizedAlways' : 'authorizedWhenInUse');
|
|
151
|
+
}
|
|
152
|
+
}], {
|
|
153
|
+
onDismiss: () => {
|
|
154
|
+
callback('authorizedWhenInUse');
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
} else {
|
|
158
|
+
const permission = await requestBackgroundLocationPermission();
|
|
159
|
+
callback(permission ? 'authorizedAlways' : 'authorizedWhenInUse');
|
|
160
|
+
}
|
|
161
|
+
} else {
|
|
162
|
+
callback('denied');
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
export const openAppSettings = () => {
|
|
169
|
+
OkHiNativeModule.openAppSettings();
|
|
170
|
+
};
|
|
171
|
+
export const retriveLocationPermissionStatus = async () => {
|
|
172
|
+
const alwaysPerm = await isBackgroundLocationPermissionGranted();
|
|
173
|
+
|
|
174
|
+
if (alwaysPerm) {
|
|
175
|
+
return 'authorizedAlways';
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const whenInUsePerm = await isLocationPermissionGranted();
|
|
179
|
+
return whenInUsePerm ? 'authorizedWhenInUse' : 'denied';
|
|
180
|
+
};
|
|
127
181
|
//# sourceMappingURL=Helpers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["Helpers.ts"],"names":["OkHiNativeModule","PermissionsAndroid","Platform","errorHandler","isValidPlatform","isLocationServicesEnabled","isLocationPermissionGranted","isBackgroundLocationPermissionGrantedAndroid","sdkVersion","getSystemVersion","hasPermission","check","PERMISSIONS","ACCESS_BACKGROUND_LOCATION","isBackgroundLocationPermissionGrantedIOS","isBackgroundLocationPermissionGranted","fn","OS","requestLocationPermissionAndroid","status","requestMultiple","ACCESS_FINE_LOCATION","ACCESS_COARSE_LOCATION","requestLocationPermissionIOS","requestLocationPermission","isGranted","requestBackgroundLocationPermissionAndroid","permissions","requestBackgroundLocationPermissionIOS","requestBackgroundLocationPermission","requestEnableLocationServices","isGooglePlayServicesAvailable","requestEnableGooglePlayServices"],"mappings":"AAAA,SAASA,gBAAT,QAAiC,qBAAjC;AACA,SAASC,kBAAT,EAA6BC,QAA7B,QAA6C,cAA7C;AACA,SAASC,YAAT,EAAuBC,eAAvB,QAA8C,YAA9C;AAEA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,yBAAyB,GAAG,MAAwB;AAC/D,SAAOD,eAAe,CAACJ,gBAAgB,CAACK,yBAAlB,CAAtB;AACD,CAFM;AAIP;AACA;AACA;AACA;;AACA,OAAO,MAAMC,2BAA2B,GAAG,MAAwB;AACjE,SAAOF,eAAe,CAACJ,gBAAgB,CAACM,2BAAlB,CAAtB;AACD,CAFM;;AAIP,MAAMC,4CAA4C,GAChD,YAA8B;AAC5B,QAAMC,UAAU,GAAG,MAAMR,gBAAgB,CAACS,gBAAjB,EAAzB;;AACA,MAAID,UAAU,GAAG,EAAjB,EAAqB;AACnB,WAAO,IAAP;AACD;;AACD,MAAIA,UAAU,GAAG,EAAjB,EAAqB;AACnB,WAAO,MAAMF,2BAA2B,EAAxC;AACD;;AACD,QAAMI,aAAa,GAAG,MAAMT,kBAAkB,CAACU,KAAnB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W,WAAnB,CAA+BC,0BADR,CAAzB;AAGA,UAAMM,MAAW,GAAG,MAAMlB,kBAAkB,CAACmB,eAAnB,CAAmCO,WAAnC,CAA1B;AACA,WACER,MAAM,CAAC,+CAAD,CAAN,KAA4D,SAD9D;AAGD,GARD,MAQO;AACL,WAAO,MAAMD,gCAAgC,EAA7C;AACD;AACF,CAfH;;AAiBA,MAAMU,sCAAsC,GAAG,MAAwB;AACrE,SAAO5B,gBAAgB,CAAC6B,mCAAjB,EAAP;AACD,CAFD;AAIA;AACA;AACA;AACA;;;AACA,OAAO,MAAMA,mCAAmC,GAC9C,YAA8B;AAC5B,QAAMJ,SAAS,GAAG,MAAMV,qCAAqC,EAA7D;AACA,MAAIU,SAAJ,EAAe,OAAOA,SAAP;AACf,SAAOtB,YAAY,CACjBD,QAAQ,CAACe,EAAT,KAAgB,SAAhB,GACIS,0CADJ,GAEIE,sCAHa,CAAnB;AAKD,CATI;AAWP;AACA;AACA;AACA;;AACA,OAAO,MAAME,6BAA6B,GAAG,MAA+B;AAC1E,SAAO1B,eAAe,CAACJ,gBAAgB,CAAC8B,6BAAlB,CAAtB;AACD,CAFM;AAIP;AACA;AACA;AACA;;AACA,OAAO,MAAMC,6BAA6B,GAAG,MAAwB;AACnE,SAAO3B,eAAe,CACpBJ,gBAAgB,CAAC+B,6BADG,EAEpB,SAFoB,CAAtB;AAID,CALM;AAOP;AACA;AACA;AACA;;AACA,OAAO,MAAMC,+BAA+B,GAAG,MAAwB;AACrE,SAAO5B,eAAe,CACpBJ,gBAAgB,CAACgC,+BADG,EAEpB,SAFoB,CAAtB;AAID,CALM;AAOP;AACA;AACA;AACA;;AACA,OAAO,MAAMvB,gBAAgB,GAAG,MAC9BL,eAAe,CAACJ,gBAAgB,CAACS,gBAAlB,CADV","sourcesContent":["import { OkHiNativeModule } from '../OkHiNativeModule';\nimport { PermissionsAndroid, Platform } from 'react-native';\nimport { errorHandler, isValidPlatform } from './_helpers';\n\n/**\n * Checks whether location services are enabled\n * @returns {Promise<boolean>} A promise that resolves to a boolen value indicating whether the service is available\n */\nexport const isLocationServicesEnabled = (): Promise<boolean> => {\n return isValidPlatform(OkHiNativeModule.isLocationServicesEnabled);\n};\n\n/**\n * Checks whether when in use location permission is granted\n * @returns {Promise<boolean>} A promise that resolves to a boolen value indicating whether the permission is granted\n */\nexport const isLocationPermissionGranted = (): Promise<boolean> => {\n return isValidPlatform(OkHiNativeModule.isLocationPermissionGranted);\n};\n\nconst isBackgroundLocationPermissionGrantedAndroid =\n async (): Promise<boolean> => {\n const sdkVersion = await OkHiNativeModule.getSystemVersion();\n if (sdkVersion < 23) {\n return true;\n }\n if (sdkVersion < 29) {\n return await isLocationPermissionGranted();\n }\n const hasPermission = await PermissionsAndroid.check(\n PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION\n );\n return hasPermission;\n };\n\nconst isBackgroundLocationPermissionGrantedIOS = (): Promise<boolean> => {\n return OkHiNativeModule.isBackgroundLocationPermissionGranted();\n};\n\n/**\n * Checks whether background location permission is granted\n * @returns {Promise<boolean>} A promise that resolves to a boolen value indicating whether the permission is granted\n */\nexport const isBackgroundLocationPermissionGranted = (): Promise<boolean> => {\n const fn =\n Platform.OS === 'android'\n ? isBackgroundLocationPermissionGrantedAndroid\n : isBackgroundLocationPermissionGrantedIOS;\n return isValidPlatform(fn);\n};\n\nconst requestLocationPermissionAndroid = async (): Promise<boolean> => {\n const status: any = await PermissionsAndroid.requestMultiple([\n PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,\n PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION,\n ]);\n return status['android.permission.ACCESS_FINE_LOCATION'] === 'granted';\n};\n\nconst requestLocationPermissionIOS = (): Promise<boolean> => {\n return OkHiNativeModule.requestLocationPermission();\n};\n\n/**\n * Requests for when in use location permission\n * @returns {Promise<boolean>} A promise that resolves to a boolen value indicating whether the permission is granted\n */\nexport const requestLocationPermission = async (): Promise<boolean> => {\n const isGranted = await isLocationPermissionGranted();\n if (isGranted) return isGranted;\n return errorHandler(\n Platform.OS === 'android'\n ? requestLocationPermissionAndroid\n : requestLocationPermissionIOS\n );\n};\n\nconst requestBackgroundLocationPermissionAndroid =\n async (): Promise<boolean> => {\n const sdkVersion = await OkHiNativeModule.getSystemVersion();\n if (sdkVersion < 23) return true;\n if (sdkVersion >= 29) {\n const permissions: any = [\n PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION,\n ];\n const status: any = await PermissionsAndroid.requestMultiple(permissions);\n return (\n status['android.permission.ACCESS_BACKGROUND_LOCATION'] === 'granted'\n );\n } else {\n return await requestLocationPermissionAndroid();\n }\n };\n\nconst requestBackgroundLocationPermissionIOS = (): Promise<boolean> => {\n return OkHiNativeModule.requestBackgroundLocationPermission();\n};\n\n/**\n * Requests for background location permission\n * @returns {Promise<boolean>} A promise that resolves to a boolen value indicating whether the permission is granted\n */\nexport const requestBackgroundLocationPermission =\n async (): Promise<boolean> => {\n const isGranted = await isBackgroundLocationPermissionGranted();\n if (isGranted) return isGranted;\n return errorHandler(\n Platform.OS === 'android'\n ? requestBackgroundLocationPermissionAndroid\n : requestBackgroundLocationPermissionIOS\n );\n };\n\n/**\n * Requests the user to enable location services by showing an in app modal on android and opening location settings on iOS\n * @returns {Promise<boolean>} A promise that resolves to either a boolean value on android or null on iOS\n */\nexport const requestEnableLocationServices = (): Promise<boolean | null> => {\n return isValidPlatform(OkHiNativeModule.requestEnableLocationServices);\n};\n\n/**\n * Android Only - Checks if Google Play Services is available\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service is avaialbe\n */\nexport const isGooglePlayServicesAvailable = (): Promise<boolean> => {\n return isValidPlatform(\n OkHiNativeModule.isGooglePlayServicesAvailable,\n 'android'\n );\n};\n\n/**\n * Android Only - Requests user to enable Google Play Services\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service is avaialbe\n */\nexport const requestEnableGooglePlayServices = (): Promise<boolean> => {\n return isValidPlatform(\n OkHiNativeModule.requestEnableGooglePlayServices,\n 'android'\n );\n};\n\n/**\n * Returns the system version of the current platform\n * @returns {Promise<boolean>} A promise that resolves either a string on iOS or number on Android\n */\nexport const getSystemVersion = (): Promise<string | number> =>\n isValidPlatform(OkHiNativeModule.getSystemVersion);\n"]}
|
|
1
|
+
{"version":3,"sources":["Helpers.ts"],"names":["OkHiNativeModule","OkHiNativeEvents","Alert","PermissionsAndroid","Platform","errorHandler","isValidPlatform","isLocationServicesEnabled","isLocationPermissionGranted","isBackgroundLocationPermissionGrantedAndroid","sdkVersion","getSystemVersion","hasPermission","check","PERMISSIONS","ACCESS_BACKGROUND_LOCATION","isBackgroundLocationPermissionGrantedIOS","isBackgroundLocationPermissionGranted","fn","OS","requestLocationPermissionAndroid","status","requestMultiple","ACCESS_FINE_LOCATION","ACCESS_COARSE_LOCATION","requestLocationPermissionIOS","requestLocationPermission","isGranted","requestBackgroundLocationPermissionAndroid","permissions","requestBackgroundLocationPermissionIOS","requestBackgroundLocationPermission","requestEnableLocationServices","isGooglePlayServicesAvailable","requestEnableGooglePlayServices","request","locationPermissionType","rationale","callback","removeAllListeners","addListener","then","result","whenInUseResult","version","alert","title","text","successButton","label","onPress","onDismiss","permission","openAppSettings","retriveLocationPermissionStatus","alwaysPerm","whenInUsePerm"],"mappings":"AAAA,SAASA,gBAAT,EAA2BC,gBAA3B,QAAmD,qBAAnD;AACA,SAASC,KAAT,EAAgBC,kBAAhB,EAAoCC,QAApC,QAAoD,cAApD;AACA,SAASC,YAAT,EAAuBC,eAAvB,QAA8C,YAA9C;;AAOA;AACA;AACA;AACA;AACA,OAAO,MAAMC,yBAAyB,GAAG,MAAwB;AAC/D,SAAOD,eAAe,CAACN,gBAAgB,CAACO,yBAAlB,CAAtB;AACD,CAFM;AAIP;AACA;AACA;AACA;;AACA,OAAO,MAAMC,2BAA2B,GAAG,MAAwB;AACjE,SAAOF,eAAe,CAACN,gBAAgB,CAACQ,2BAAlB,CAAtB;AACD,CA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AACAO,gBAAAA,QAAQ,CACNI,MAAM,GAAG,kBAAH,GAAwB,qBADxB,CAAR;AAGD;AATH,aADF,CAHF,EAgBE;AACES,cAAAA,SAAS,EAAE,MAAM;AACfb,gBAAAA,QAAQ,CAAC,qBAAD,CAAR;AACD;AAHH,aAhBF;AAsBD,WAvBD,MAuBO;AACL,kBAAMc,UAAU,GAAG,MAAMrB,mCAAmC,EAA5D;AACAO,YAAAA,QAAQ,CAACc,UAAU,GAAG,kBAAH,GAAwB,qBAAnC,CAAR;AACD;AACF,SA7BD,MA6BO;AACLd,UAAAA,QAAQ,CAAC,QAAD,CAAR;AACD;AACF,OAjCD;AAkCD;AACF;AACF,CA3DM;AA6DP,OAAO,MAAMe,eAAe,GAAG,MAAM;AACnCrD,EAAAA,gBAAgB,CAACqD,eAAjB;AACD,CAFM;AAIP,OAAO,MAAMC,+BAA+B,GAC1C,YAA+C;AAC7C,QAAMC,UAAU,GAAG,MAAMtC,qCAAqC,EAA9D;;AACA,MAAIsC,UAAJ,EAAgB;AACd,WAAO,kBAAP;AACD;;AACD,QAAMC,aAAa,GAAG,MAAMhD,2BAA2B,EAAvD;AACA,SAAOgD,aAAa,GAAG,qBAAH,GAA2B,QAA/C;AACD,CARI","sourcesContent":["import { OkHiNativeModule, OkHiNativeEvents } from '../OkHiNativeModule';\nimport { Alert, PermissionsAndroid, Platform } from 'react-native';\nimport { errorHandler, isValidPlatform } from './_helpers';\nimport type {\n LocationPermissionCallback,\n LocationPermissionStatus,\n LocationRequestPermissionType,\n} from './types';\n\n/**\n * Checks whether location services are enabled\n * @returns {Promise<boolean>} A promise that resolves to a boolen value indicating whether the service is available\n */\nexport const isLocationServicesEnabled = (): Promise<boolean> => {\n return isValidPlatform(OkHiNativeModule.isLocationServicesEnabled);\n};\n\n/**\n * Checks whether when in use location permission is granted\n * @returns {Promise<boolean>} A promise that resolves to a boolen value indicating whether the permission is granted\n */\nexport const isLocationPermissionGranted = (): Promise<boolean> => {\n return isValidPlatform(OkHiNativeModule.isLocationPermissionGranted);\n};\n\nconst isBackgroundLocationPermissionGrantedAndroid =\n async (): Promise<boolean> => {\n const sdkVersion = await OkHiNativeModule.getSystemVersion();\n if (sdkVersion < 23) {\n return true;\n }\n if (sdkVersion < 29) {\n return await isLocationPermissionGranted();\n }\n const hasPermission = await PermissionsAndroid.check(\n PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION\n );\n return hasPermission;\n };\n\nconst isBackgroundLocationPermissionGrantedIOS = (): Promise<boolean> => {\n return OkHiNativeModule.isBackgroundLocationPermissionGranted();\n};\n\n/**\n * Checks whether background location permission is granted\n * @returns {Promise<boolean>} A promise that resolves to a boolen value indicating whether the permission is granted\n */\nexport const isBackgroundLocationPermissionGranted = (): Promise<boolean> => {\n const fn =\n Platform.OS === 'android'\n ? isBackgroundLocationPermissionGrantedAndroid\n : isBackgroundLocationPermissionGrantedIOS;\n return isValidPlatform(fn);\n};\n\nconst requestLocationPermissionAndroid = async (): Promise<boolean> => {\n const status: any = await PermissionsAndroid.requestMultiple([\n PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,\n PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION,\n ]);\n return status['android.permission.ACCESS_FINE_LOCATION'] === 'granted';\n};\n\nconst requestLocationPermissionIOS = (): Promise<boolean> => {\n return OkHiNativeModule.requestLocationPermission();\n};\n\n/**\n * Requests for when in use location permission\n * @returns {Promise<boolean>} A promise that resolves to a boolen value indicating whether the permission is granted\n */\nexport const requestLocationPermission = async (): Promise<boolean> => {\n const isGranted = await isLocationPermissionGranted();\n if (isGranted) return isGranted;\n return errorHandler(\n Platform.OS === 'android'\n ? requestLocationPermissionAndroid\n : requestLocationPermissionIOS\n );\n};\n\nconst requestBackgroundLocationPermissionAndroid =\n async (): Promise<boolean> => {\n const sdkVersion = await OkHiNativeModule.getSystemVersion();\n if (sdkVersion < 23) return true;\n if (sdkVersion >= 29) {\n const permissions: any = [\n PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION,\n ];\n const status: any = await PermissionsAndroid.requestMultiple(permissions);\n return (\n status['android.permission.ACCESS_BACKGROUND_LOCATION'] === 'granted'\n );\n } else {\n return await requestLocationPermissionAndroid();\n }\n };\n\nconst requestBackgroundLocationPermissionIOS = (): Promise<boolean> => {\n return OkHiNativeModule.requestBackgroundLocationPermission();\n};\n\n/**\n * Requests for background location permission\n * @returns {Promise<boolean>} A promise that resolves to a boolen value indicating whether the permission is granted\n */\nexport const requestBackgroundLocationPermission =\n async (): Promise<boolean> => {\n const isGranted = await isBackgroundLocationPermissionGranted();\n if (isGranted) return isGranted;\n return errorHandler(\n Platform.OS === 'android'\n ? requestBackgroundLocationPermissionAndroid\n : requestBackgroundLocationPermissionIOS\n );\n };\n\n/**\n * Requests the user to enable location services by showing an in app modal on android and opening location settings on iOS\n * @returns {Promise<boolean>} A promise that resolves to either a boolean value on android or null on iOS\n */\nexport const requestEnableLocationServices = (): Promise<boolean | null> => {\n return isValidPlatform(OkHiNativeModule.requestEnableLocationServices);\n};\n\n/**\n * Android Only - Checks if Google Play Services is available\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service is avaialbe\n */\nexport const isGooglePlayServicesAvailable = (): Promise<boolean> => {\n return isValidPlatform(\n OkHiNativeModule.isGooglePlayServicesAvailable,\n 'android'\n );\n};\n\n/**\n * Android Only - Requests user to enable Google Play Services\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service is avaialbe\n */\nexport const requestEnableGooglePlayServices = (): Promise<boolean> => {\n return isValidPlatform(\n OkHiNativeModule.requestEnableGooglePlayServices,\n 'android'\n );\n};\n\n/**\n * Returns the system version of the current platform\n * @returns {Promise<boolean>} A promise that resolves either a string on iOS or number on Android\n */\nexport const getSystemVersion = (): Promise<string | number> =>\n isValidPlatform(OkHiNativeModule.getSystemVersion);\n\nexport const request = (\n locationPermissionType: LocationRequestPermissionType,\n rationale: {\n title: string;\n text: string;\n successButton?: { label: string };\n } | null,\n callback: LocationPermissionCallback\n) => {\n if (Platform.OS === 'ios') {\n OkHiNativeEvents.removeAllListeners('onLocationPermissionStatusUpdate');\n OkHiNativeEvents.addListener('onLocationPermissionStatusUpdate', callback);\n if (locationPermissionType === 'whenInUse') {\n OkHiNativeModule.requestLocationPermission();\n } else {\n OkHiNativeModule.requestBackgroundLocationPermission();\n }\n } else {\n if (locationPermissionType === 'whenInUse') {\n requestLocationPermissionAndroid().then((result) =>\n callback(result ? 'authorizedWhenInUse' : 'denied')\n );\n } else {\n requestLocationPermissionAndroid().then(async (whenInUseResult) => {\n if (whenInUseResult) {\n const version = await getSystemVersion();\n if (version >= 30 && rationale) {\n Alert.alert(\n rationale.title,\n rationale.text,\n [\n {\n text: rationale.successButton\n ? rationale.successButton.label\n : 'Okay',\n onPress: async () => {\n const result = await requestBackgroundLocationPermission();\n callback(\n result ? 'authorizedAlways' : 'authorizedWhenInUse'\n );\n },\n },\n ],\n {\n onDismiss: () => {\n callback('authorizedWhenInUse');\n },\n }\n );\n } else {\n const permission = await requestBackgroundLocationPermission();\n callback(permission ? 'authorizedAlways' : 'authorizedWhenInUse');\n }\n } else {\n callback('denied');\n }\n });\n }\n }\n};\n\nexport const openAppSettings = () => {\n OkHiNativeModule.openAppSettings();\n};\n\nexport const retriveLocationPermissionStatus =\n async (): Promise<LocationPermissionStatus> => {\n const alwaysPerm = await isBackgroundLocationPermissionGranted();\n if (alwaysPerm) {\n return 'authorizedAlways';\n }\n const whenInUsePerm = await isLocationPermissionGranted();\n return whenInUsePerm ? 'authorizedWhenInUse' : 'denied';\n };\n"]}
|
|
@@ -19,9 +19,12 @@ export class OkHiAuth {
|
|
|
19
19
|
_defineProperty(this, "SANDBOX_BASE_URL", `https://sandbox-api.okhi.io/${this.API_VERSION}` + this.ANONYMOUS_SIGN_IN_ENDPOINT);
|
|
20
20
|
|
|
21
21
|
_defineProperty(this, "PROD_BASE_URL", `https://api.okhi.io/${this.API_VERSION}` + this.ANONYMOUS_SIGN_IN_ENDPOINT);
|
|
22
|
+
|
|
23
|
+
_defineProperty(this, "config", null);
|
|
22
24
|
}
|
|
23
25
|
|
|
24
|
-
anonymousSignInWithPhoneNumber(phone, scopes) {
|
|
26
|
+
anonymousSignInWithPhoneNumber(phone, scopes, config) {
|
|
27
|
+
this.config = config;
|
|
25
28
|
return this.anonymousSignIn({
|
|
26
29
|
scopes,
|
|
27
30
|
phone
|
|
@@ -38,7 +41,7 @@ export class OkHiAuth {
|
|
|
38
41
|
async anonymousSignIn(payload) {
|
|
39
42
|
return new Promise(async (resolve, reject) => {
|
|
40
43
|
try {
|
|
41
|
-
const config = await getApplicationConfiguration();
|
|
44
|
+
const config = this.config || (await getApplicationConfiguration());
|
|
42
45
|
|
|
43
46
|
if (config === null || !config.auth || !config.auth.token) {
|
|
44
47
|
reject(new OkHiException({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["OkHiAuth.ts"],"names":["axios","OkHiMode","OkHiException","getApplicationConfiguration","OkHiAuth","API_VERSION","ANONYMOUS_SIGN_IN_ENDPOINT","anonymousSignInWithPhoneNumber","phone","scopes","anonymousSignIn","anonymousSignInWithUserId","userId","user_id","payload","Promise","resolve","reject","
|
|
1
|
+
{"version":3,"sources":["OkHiAuth.ts"],"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"],"mapp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AAK,CAACE,QAAN,CAAeG,MAAvB;AACE,WAAK,GAAL;AACE,eAAO,IAAIxC,aAAJ,CAAkB;AACvBmB,UAAAA,IAAI,EAAEnB,aAAa,CAACyC,kBADG;AAEvBpB,UAAAA,OAAO,EAAErB,aAAa,CAAC0C;AAFA,SAAlB,CAAP;;AAIF,WAAK,GAAL;AACE,eAAO,IAAI1C,aAAJ,CAAkB;AACvBmB,UAAAA,IAAI,EAAEnB,aAAa,CAACoB,iBADG;AAEvBC,UAAAA,OAAO,EAAErB,aAAa,CAACsB;AAFA,SAAlB,CAAP;;AAIF;AACE,eAAO,IAAItB,aAAJ,CAAkB;AACvBmB,UAAAA,IAAI,EAAEnB,aAAa,CAAC2C,kBADG;AAEvBtB,UAAAA,OAAO,EAAEc,KAAK,CAACd,OAAN,IAAiBrB,aAAa,CAAC4C;AAFjB,SAAlB,CAAP;AAZJ;AAiBD;;AA/FmB","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"]}
|
|
@@ -5,6 +5,14 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
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
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Error is thrown when play services is unavailable.
|
|
14
|
+
*/
|
|
15
|
+
|
|
8
16
|
/**
|
|
9
17
|
* Error is thrown when the device can't connect to OkHi's servers.
|
|
10
18
|
*/
|
|
@@ -82,6 +90,10 @@ export class OkHiException extends Error {
|
|
|
82
90
|
|
|
83
91
|
}
|
|
84
92
|
|
|
93
|
+
_defineProperty(OkHiException, "LOCATION_SERVICES_UNAVAILABLE_CODE", 'location_services_unavailable');
|
|
94
|
+
|
|
95
|
+
_defineProperty(OkHiException, "PLAY_SERVICES_UNAVAILABLE_CODE", 'play_services_unavailable');
|
|
96
|
+
|
|
85
97
|
_defineProperty(OkHiException, "NETWORK_ERROR_CODE", 'network_error');
|
|
86
98
|
|
|
87
99
|
_defineProperty(OkHiException, "NETWORK_ERROR_MESSAGE", 'Unable to establish a connection with OkHi servers');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["OkHiException.ts"],"names":["OkHiException","Error","constructor","error","message","name","code"],"mappings":";;AAEA;AACA;AACA;AACA;AACA,OAAO,MAAMA,aAAN,SAA4BC,KAA5B,CAAkC;AACvC;AACF;AACA;;AAEE;AACF;AACA;;AAGE;AACF;AACA;;AAEE;AACF;AACA;;AAGE;AACF;AACA;;AAEE;AACF;AACA;;AAGE;AACF;AACA;;AAEE;AACF;AACA;;AAEE;AACF;AACA;;AAEE;AACF;AACA;;AAEE;AACF;AACA;;AAEE;AACF;AACA;;AAEE;AACF;AACA;;AAEE;AACF;AACA;;AAGE;AACF;AACA;;AAGE;AACF;AACA;AACA;AACA;AACEC,EAAAA,WAAW,CAACC,KAAD,EAAmB;AAC5B,UAAMA,KAAK,CAACC,OAAZ;;AAD4B;;AAE5B,SAAKC,IAAL,GAAY,eAAZ;AACA,SAAKD,OAAL,GAAeD,KAAK,CAACC,OAArB;AACA,SAAKE,IAAL,GAAYH,KAAK,CAACG,IAAlB;AACD;;
|
|
1
|
+
{"version":3,"sources":["OkHiException.ts"],"names":["OkHiException","Error","constructor","error","message","name","code"],"mappings":";;AAEA;AACA;AACA;AACA;AACA,OAAO,MAAMA,aAAN,SAA4BC,KAA5B,CAAkC;AACvC;AACF;AACA;;AAGE;AACF;AACA;;AAEE;AACF;AACA;;AAEE;AACF;AACA;;AAGE;AACF;AACA;;AAEE;AACF;AACA;;AAGE;AACF;AACA;;AAEE;AACF;AACA;;AAGE;AACF;AACA;;AAEE;AACF;AACA;;AAEE;AACF;AACA;;AAEE;AACF;AACA;;AAEE;AACF;AACA;;AAEE;AACF;AACA;;AAEE;AACF;AACA;;AAEE;AACF;AACA;;AAGE;AACF;AACA;;AAGE;AACF;AACA;AACA;AACA;AACEC,EAAAA,WAAW,CAACC,KAAD,EAAmB;AAC5B,UAAMA,KAAK,CAACC,OAAZ;;AAD4B;;AAE5B,SAAKC,IAAL,GAAY,eAAZ;AACA,SAAKD,OAAL,GAAeD,KAAK,CAACC,OAArB;AACA,SAAKE,IAAL,GAAYH,KAAK,CAACG,IAAlB;AACD;;AArFsC;;gBAA5BN,a,wCAIiC,+B;;gBAJjCA,a,oCAS6B,2B;;gBAT7BA,a,wBAaiB,e;;gBAbjBA,a,2BAkBT,oD;;gBAlBSA,a,wBAsBiB,e;;gBAtBjBA,a,2BA2BT,qD;;gBA3BSA,a,wBA+BiB,e;;gBA/BjBA,a,2BAoCT,+E;;gBApCSA,a,uBAwCgB,c;;gBAxChBA,a,0BA4CmB,8B;;gBA5CnBA,a,4BAgDqB,mB;;gBAhDrBA,a,8BAoDuB,qB;;gBApDvBA,a,+BAwDwB,sB;;gBAxDxBA,a,kCA4D2B,mC;;gBA5D3BA,a,sBAgEe,a;;gBAhEfA,a,yBAoEkB,6B","sourcesContent":["import type { OkHiError } from './types';\n\n/**\n * The OkHiException class extends the Error class to provide additional information regarding the type of errors thrown while running any OkHiLibraries.\n * It contains static string properties that can be used to evaluate the kind of errors being thrown and handle them appropriately.\n */\nexport class OkHiException extends Error {\n /**\n * Error is thrown when location services is unavailable.\n */\n static LOCATION_SERVICES_UNAVAILABLE_CODE = 'location_services_unavailable';\n\n /**\n * Error is thrown when play services is unavailable.\n */\n static PLAY_SERVICES_UNAVAILABLE_CODE = 'play_services_unavailable';\n /**\n * Error is thrown when the device can't connect to OkHi's servers.\n */\n static NETWORK_ERROR_CODE = 'network_error';\n /**\n * Error is thrown when the device can't connect to OkHi's servers.\n */\n static NETWORK_ERROR_MESSAGE =\n 'Unable to establish a connection with OkHi servers';\n /**\n * Error is thrown whenever there's an unknown error that occured during the usage of one of OkHi's services.\n */\n static UNKNOWN_ERROR_CODE = 'unknown_error';\n /**\n * Error is thrown whenever there's an unknown error that occured during the usage of one of OkHi's services.\n */\n static UNKNOWN_ERROR_MESSAGE =\n 'Unable to process the request. Something went wrong';\n /**\n * Error is thrown whenever an invalid phone number is provided to a service that requires a user's phone number.\n */\n static INVALID_PHONE_CODE = 'invalid_phone';\n /**\n * Error is thrown whenever an invalid phone number is provided to a service that requires a user's phone number.\n */\n static INVALID_PHONE_MESSAGE =\n 'Invalid phone number provided. Please make sure its in MSISDN standard format';\n /**\n * Error is thrown whenever there's an issue with the credentials provided.\n */\n static UNAUTHORIZED_CODE = 'unauthorized';\n /**\n * Error is thrown whenever there's an issue with the credentials provided.\n */\n static UNAUTHORIZED_MESSAGE = 'Invalid credentials provided';\n /**\n * Error is thrown whenever a particular permission is required for a service to run and isn't granted by the user.\n */\n static PERMISSION_DENIED_CODE = 'permission_denied';\n /**\n * Error is thrown whenever a particular device service is required for a library to run and isn't granted by the user.\n */\n static SERVICE_UNAVAILABLE_CODE = 'service_unavailable';\n /**\n * Error is thrown whenever an OkHi service is run on an unsupported platform.\n */\n static UNSUPPORTED_PLATFORM_CODE = 'unsupported_platform';\n /**\n * Error is thrown whenever an OkHi service is run on an unsupported platform.\n */\n static UNSUPPORTED_PLATFORM_MESSAGE = 'Current platform is not supported';\n /**\n * Error is thrown whenever bad configuration is provided to an OkHi service.\n */\n static BAD_REQUEST_CODE = 'bad_request';\n /**\n * Error is thrown whenever bad configuration is provided to an OkHi service.\n */\n static BAD_REQUEST_MESSAGE = 'Invalid parameters provided';\n\n /**\n * Specific error code string detailing the kind of error being thrown.\n */\n code: string;\n\n /**\n * @param error An error object with code and respective message.\n * @param error.code Specific error code string detailing the kind of error being thrown.\n * @param error.message Specific error message string detailing the kind of error being thrown.\n */\n constructor(error: OkHiError) {\n super(error.message);\n this.name = 'OkHiException';\n this.message = error.message;\n this.code = error.code;\n }\n}\n"]}
|
|
@@ -14,13 +14,13 @@ let okhiApplicationConfiguration;
|
|
|
14
14
|
|
|
15
15
|
export function initialize(configuration) {
|
|
16
16
|
return errorHandler(async () => {
|
|
17
|
+
okhiApplicationConfiguration = configuration;
|
|
18
|
+
|
|
17
19
|
if (Platform.OS === 'android') {
|
|
18
20
|
await OkHiNativeModule.initialize(JSON.stringify(configuration));
|
|
19
21
|
} else {
|
|
20
22
|
await OkHiNativeModule.initializeIOS(configuration.credentials.branchId, configuration.credentials.clientKey, configuration.context.mode);
|
|
21
23
|
}
|
|
22
|
-
|
|
23
|
-
okhiApplicationConfiguration = configuration;
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.ts"],"names":["Platform","OkHiNativeModule","errorHandler","okhiApplicationConfiguration","initialize","configuration","OS","JSON","stringify","initializeIOS","credentials","branchId","clientKey","context","mode","getApplicationConfiguration","auth","token","getAuthToken","error"],"mappings":"AAAA,SAASA,QAAT,QAAyB,cAAzB;AACA,SAASC,gBAAT,QAAiC,qBAAjC;AAEA,SAASC,YAAT,QAA6B,YAA7B;AAGA,cAAc,SAAd;AACA,cAAc,iBAAd;AACA,cAAc,YAAd;AACA,cAAc,WAAd;AAEA,IAAIC,4BAAJ;AAEA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,UAAT,CACLC,aADK,EAEU;AACf,SAAOH,YAAY,CAAC,YAAY;
|
|
1
|
+
{"version":3,"sources":["index.ts"],"names":["Platform","OkHiNativeModule","errorHandler","okhiApplicationConfiguration","initialize","configuration","OS","JSON","stringify","initializeIOS","credentials","branchId","clientKey","context","mode","getApplicationConfiguration","auth","token","getAuthToken","error"],"mappings":"AAAA,SAASA,QAAT,QAAyB,cAAzB;AACA,SAASC,gBAAT,QAAiC,qBAAjC;AAEA,SAASC,YAAT,QAA6B,YAA7B;AAGA,cAAc,SAAd;AACA,cAAc,iBAAd;AACA,cAAc,YAAd;AACA,cAAc,WAAd;AAEA,IAAIC,4BAAJ;AAEA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,UAAT,CACLC,aADK,EAEU;AACf,SAAOH,YAAY,CAAC,YAAY;AAC9BC,IAAAA,4BAA4B,GAAGE,aAA/B;;AACA,QAAIL,QAAQ,CAACM,EAAT,KAAgB,SAApB,EAA+B;AAC7B,YAAML,gBAAgB,CAACG,UAAjB,CAA4BG,IAAI,CAACC,SAAL,CAAeH,aAAf,CAA5B,CAAN;AACD,KAFD,MAEO;AACL,YAAMJ,gBAAgB,CAACQ,aAAjB,CACJJ,aAAa,CAACK,WAAd,CAA0BC,QADtB,EAEJN,aAAa,CAACK,WAAd,CAA0BE,SAFtB,EAGJP,aAAa,CAACQ,OAAd,CAAsBC,IAHlB,CAAN;AAKD;AACF,GAXkB,CAAnB;AAYD;AAED;AACA;AACA;AACA;;AACA,OAAO,eAAeC,2BAAf,GAAoF;AACzF,MAAI;AACF,QAAI,OAAOZ,4BAAP,KAAwC,QAA5C,EAAsD;AAAA;;AACpD,aAAO,EACL,GAAGA,4BADE;AAELa,QAAAA,IAAI,EAAE;AACJC,UAAAA,KAAK,EAAE,MAAMhB,gBAAgB,CAACiB,YAAjB,CACX,0BAAAf,4BAA4B,UAA5B,sEAA8BO,WAA9B,CAA0CC,QAA1C,KAAsD,EAD3C,EAEX,2BAAAR,4BAA4B,UAA5B,wEAA8BO,WAA9B,CAA0CE,SAA1C,KAAuD,EAF5C;AADT;AAFD,OAAP;AASD;;AACD,WAAO,IAAP;AACD,GAbD,CAaE,OAAOO,KAAP,EAAc;AACd,UAAMA,KAAN;AACD;AACF","sourcesContent":["import { Platform } from 'react-native';\nimport { OkHiNativeModule } from '../OkHiNativeModule';\nimport type { OkHiApplicationConfiguration } from './types';\nimport { errorHandler } from './_helpers';\nimport type { AuthApplicationConfig } from './_types';\n\nexport * from './types';\nexport * from './OkHiException';\nexport * from './OkHiMode';\nexport * from './Helpers';\n\nlet okhiApplicationConfiguration: OkHiApplicationConfiguration | undefined;\n\n/**\n * Initializes the OkHi library with provided API keys\n * @param {Object} configuration A configuration object with your OkHi credentials as well as library settings\n * @returns {Promise<void>} A promise that resolves when initialization is successful\n */\nexport function initialize(\n configuration: OkHiApplicationConfiguration\n): Promise<void> {\n return errorHandler(async () => {\n okhiApplicationConfiguration = configuration;\n if (Platform.OS === 'android') {\n await OkHiNativeModule.initialize(JSON.stringify(configuration));\n } else {\n await OkHiNativeModule.initializeIOS(\n configuration.credentials.branchId,\n configuration.credentials.clientKey,\n configuration.context.mode\n );\n }\n });\n}\n\n/**\n * Obtains your current running configuration\n * @returns {Promise<void>} A promise that resolves with your application configuration\n */\nexport async function getApplicationConfiguration(): Promise<AuthApplicationConfig | null> {\n try {\n if (typeof okhiApplicationConfiguration === 'object') {\n return {\n ...okhiApplicationConfiguration,\n auth: {\n token: await OkHiNativeModule.getAuthToken(\n okhiApplicationConfiguration?.credentials.branchId || '',\n okhiApplicationConfiguration?.credentials.clientKey || ''\n ),\n },\n };\n }\n return null;\n } catch (error) {\n throw error;\n }\n}\n"]}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
import { NativeModules } from 'react-native';
|
|
1
|
+
import { NativeModules, NativeEventEmitter } from 'react-native';
|
|
2
2
|
export const OkHiNativeModule = NativeModules.Okhi;
|
|
3
|
+
export const OkHiNativeEvents = new NativeEventEmitter(NativeModules.Okhi);
|
|
4
|
+
OkHiNativeEvents.addListener('onLocationPermissionStatusUpdate', () => null);
|
|
3
5
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.ts"],"names":["NativeModules","OkHiNativeModule","Okhi"],"mappings":"AAAA,SAASA,aAAT,
|
|
1
|
+
{"version":3,"sources":["index.ts"],"names":["NativeModules","NativeEventEmitter","OkHiNativeModule","Okhi","OkHiNativeEvents","addListener"],"mappings":"AAAA,SAASA,aAAT,EAAwBC,kBAAxB,QAAkD,cAAlD;AAsCA,OAAO,MAAMC,gBAAsC,GAAGF,aAAa,CAACG,IAA7D;AAEP,OAAO,MAAMC,gBAAgB,GAAG,IAAIH,kBAAJ,CAAuBD,aAAa,CAACG,IAArC,CAAzB;AAEPC,gBAAgB,CAACC,WAAjB,CAA6B,kCAA7B,EAAiE,MAAM,IAAvE","sourcesContent":["import { NativeModules, NativeEventEmitter } from 'react-native';\nimport type { OkVerifyStartConfiguration } from '../OkVerify/types';\n\ntype OkHiNativeModuleType = {\n multiply(a: number, b: number): Promise<number>;\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};\n\nexport const OkHiNativeModule: OkHiNativeModuleType = NativeModules.Okhi;\n\nexport const OkHiNativeEvents = new NativeEventEmitter(NativeModules.Okhi);\n\nOkHiNativeEvents.addListener('onLocationPermissionStatusUpdate', () => null);\n"]}
|