react-native-okhi 1.0.3-2.beta.1

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.
Files changed (127) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +174 -0
  3. package/android/build.gradle +139 -0
  4. package/android/gradle.properties +5 -0
  5. package/android/src/main/AndroidManifest.xml +4 -0
  6. package/android/src/main/java/com/reactnativeokhi/OkhiModule.java +317 -0
  7. package/android/src/main/java/com/reactnativeokhi/OkhiPackage.java +28 -0
  8. package/ios/OkHiExtension.swift +27 -0
  9. package/ios/OkHiStruct.swift +29 -0
  10. package/ios/Okhi-Bridging-Header.h +3 -0
  11. package/ios/Okhi.m +41 -0
  12. package/ios/Okhi.swift +207 -0
  13. package/ios/Okhi.xcodeproj/project.pbxproj +283 -0
  14. package/ios/Okhi.xcodeproj/project.xcworkspace/contents.xcworkspacedata +4 -0
  15. package/lib/commonjs/OkCollect/Helpers.js +47 -0
  16. package/lib/commonjs/OkCollect/Helpers.js.map +1 -0
  17. package/lib/commonjs/OkCollect/OkHiLocationManager.js +202 -0
  18. package/lib/commonjs/OkCollect/OkHiLocationManager.js.map +1 -0
  19. package/lib/commonjs/OkCollect/Spinner.js +32 -0
  20. package/lib/commonjs/OkCollect/Spinner.js.map +1 -0
  21. package/lib/commonjs/OkCollect/Util.js +192 -0
  22. package/lib/commonjs/OkCollect/Util.js.map +1 -0
  23. package/lib/commonjs/OkCollect/app.json +4 -0
  24. package/lib/commonjs/OkCollect/index.js +52 -0
  25. package/lib/commonjs/OkCollect/index.js.map +1 -0
  26. package/lib/commonjs/OkCollect/types.js +6 -0
  27. package/lib/commonjs/OkCollect/types.js.map +1 -0
  28. package/lib/commonjs/OkCore/Helpers.js +367 -0
  29. package/lib/commonjs/OkCore/Helpers.js.map +1 -0
  30. package/lib/commonjs/OkCore/OkHiAuth.js +126 -0
  31. package/lib/commonjs/OkCore/OkHiAuth.js.map +1 -0
  32. package/lib/commonjs/OkCore/OkHiException.js +133 -0
  33. package/lib/commonjs/OkCore/OkHiException.js.map +1 -0
  34. package/lib/commonjs/OkCore/OkHiMode.js +16 -0
  35. package/lib/commonjs/OkCore/OkHiMode.js.map +1 -0
  36. package/lib/commonjs/OkCore/_helpers.js +50 -0
  37. package/lib/commonjs/OkCore/_helpers.js.map +1 -0
  38. package/lib/commonjs/OkCore/_types.js +2 -0
  39. package/lib/commonjs/OkCore/_types.js.map +1 -0
  40. package/lib/commonjs/OkCore/index.js +117 -0
  41. package/lib/commonjs/OkCore/index.js.map +1 -0
  42. package/lib/commonjs/OkCore/types.js +2 -0
  43. package/lib/commonjs/OkCore/types.js.map +1 -0
  44. package/lib/commonjs/OkHiNativeModule/index.js +24 -0
  45. package/lib/commonjs/OkHiNativeModule/index.js.map +1 -0
  46. package/lib/commonjs/OkVerify/index.js +246 -0
  47. package/lib/commonjs/OkVerify/index.js.map +1 -0
  48. package/lib/commonjs/OkVerify/types.js +2 -0
  49. package/lib/commonjs/OkVerify/types.js.map +1 -0
  50. package/lib/commonjs/index.js +45 -0
  51. package/lib/commonjs/index.js.map +1 -0
  52. package/lib/module/OkCollect/Helpers.js +36 -0
  53. package/lib/module/OkCollect/Helpers.js.map +1 -0
  54. package/lib/module/OkCollect/OkHiLocationManager.js +179 -0
  55. package/lib/module/OkCollect/OkHiLocationManager.js.map +1 -0
  56. package/lib/module/OkCollect/Spinner.js +20 -0
  57. package/lib/module/OkCollect/Spinner.js.map +1 -0
  58. package/lib/module/OkCollect/Util.js +171 -0
  59. package/lib/module/OkCollect/Util.js.map +1 -0
  60. package/lib/module/OkCollect/app.json +4 -0
  61. package/lib/module/OkCollect/index.js +4 -0
  62. package/lib/module/OkCollect/index.js.map +1 -0
  63. package/lib/module/OkCollect/types.js +2 -0
  64. package/lib/module/OkCollect/types.js.map +1 -0
  65. package/lib/module/OkCore/Helpers.js +315 -0
  66. package/lib/module/OkCore/Helpers.js.map +1 -0
  67. package/lib/module/OkCore/OkHiAuth.js +112 -0
  68. package/lib/module/OkCore/OkHiAuth.js.map +1 -0
  69. package/lib/module/OkCore/OkHiException.js +124 -0
  70. package/lib/module/OkCore/OkHiException.js.map +1 -0
  71. package/lib/module/OkCore/OkHiMode.js +8 -0
  72. package/lib/module/OkCore/OkHiMode.js.map +1 -0
  73. package/lib/module/OkCore/_helpers.js +38 -0
  74. package/lib/module/OkCore/_helpers.js.map +1 -0
  75. package/lib/module/OkCore/_types.js +2 -0
  76. package/lib/module/OkCore/_types.js.map +1 -0
  77. package/lib/module/OkCore/index.js +50 -0
  78. package/lib/module/OkCore/index.js.map +1 -0
  79. package/lib/module/OkCore/types.js +2 -0
  80. package/lib/module/OkCore/types.js.map +1 -0
  81. package/lib/module/OkHiNativeModule/index.js +14 -0
  82. package/lib/module/OkHiNativeModule/index.js.map +1 -0
  83. package/lib/module/OkVerify/index.js +187 -0
  84. package/lib/module/OkVerify/index.js.map +1 -0
  85. package/lib/module/OkVerify/types.js +2 -0
  86. package/lib/module/OkVerify/types.js.map +1 -0
  87. package/lib/module/index.js +4 -0
  88. package/lib/module/index.js.map +1 -0
  89. package/lib/typescript/OkCollect/Helpers.d.ts +9 -0
  90. package/lib/typescript/OkCollect/OkHiLocationManager.d.ts +6 -0
  91. package/lib/typescript/OkCollect/Spinner.d.ts +4 -0
  92. package/lib/typescript/OkCollect/Util.d.ts +26 -0
  93. package/lib/typescript/OkCollect/index.d.ts +3 -0
  94. package/lib/typescript/OkCollect/types.d.ts +133 -0
  95. package/lib/typescript/OkCore/Helpers.d.ts +82 -0
  96. package/lib/typescript/OkCore/OkHiAuth.d.ts +16 -0
  97. package/lib/typescript/OkCore/OkHiException.d.ts +81 -0
  98. package/lib/typescript/OkCore/OkHiMode.d.ts +7 -0
  99. package/lib/typescript/OkCore/_helpers.d.ts +3 -0
  100. package/lib/typescript/OkCore/_types.d.ts +38 -0
  101. package/lib/typescript/OkCore/index.d.ts +17 -0
  102. package/lib/typescript/OkCore/types.d.ts +180 -0
  103. package/lib/typescript/OkHiNativeModule/index.d.ts +34 -0
  104. package/lib/typescript/OkVerify/index.d.ts +60 -0
  105. package/lib/typescript/OkVerify/types.d.ts +5 -0
  106. package/lib/typescript/index.d.ts +3 -0
  107. package/package.json +152 -0
  108. package/react-native-okhi.podspec +36 -0
  109. package/src/OkCollect/Helpers.ts +53 -0
  110. package/src/OkCollect/OkHiLocationManager.tsx +209 -0
  111. package/src/OkCollect/Spinner.tsx +18 -0
  112. package/src/OkCollect/Util.ts +195 -0
  113. package/src/OkCollect/app.json +4 -0
  114. package/src/OkCollect/index.ts +3 -0
  115. package/src/OkCollect/types.ts +142 -0
  116. package/src/OkCore/Helpers.ts +389 -0
  117. package/src/OkCore/OkHiAuth.ts +106 -0
  118. package/src/OkCore/OkHiException.ts +93 -0
  119. package/src/OkCore/OkHiMode.ts +7 -0
  120. package/src/OkCore/_helpers.ts +48 -0
  121. package/src/OkCore/_types.ts +37 -0
  122. package/src/OkCore/index.ts +59 -0
  123. package/src/OkCore/types.ts +203 -0
  124. package/src/OkHiNativeModule/index.ts +63 -0
  125. package/src/OkVerify/index.ts +243 -0
  126. package/src/OkVerify/types.ts +3 -0
  127. package/src/index.tsx +3 -0
@@ -0,0 +1,367 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.retriveLocationPermissionStatus = exports.requestTrackingAuthorization = exports.requestLocationPermission = exports.requestEnableLocationServices = exports.requestEnableGooglePlayServices = exports.requestBackgroundLocationPermission = exports.request = exports.openProtectedAppsSettings = exports.openAppSettings = exports.isLocationServicesEnabled = exports.isLocationPermissionGranted = exports.isGooglePlayServicesAvailable = exports.isBackgroundLocationPermissionGranted = exports.getSystemVersion = exports.canOpenProtectedAppsSettings = void 0;
7
+
8
+ var _OkHiNativeModule = require("../OkHiNativeModule");
9
+
10
+ var _reactNative = require("react-native");
11
+
12
+ var _helpers = require("./_helpers");
13
+
14
+ var _OkHiException = require("./OkHiException");
15
+
16
+ /**
17
+ * Checks whether location services are enabled
18
+ * @returns {Promise<boolean>} A promise that resolves to a boolen value indicating whether the service is available
19
+ */
20
+ const isLocationServicesEnabled = () => {
21
+ return (0, _helpers.isValidPlatform)(_OkHiNativeModule.OkHiNativeModule.isLocationServicesEnabled);
22
+ };
23
+ /**
24
+ * Checks whether when in use location permission is granted
25
+ * @returns {Promise<boolean>} A promise that resolves to a boolen value indicating whether the permission is granted
26
+ */
27
+
28
+
29
+ exports.isLocationServicesEnabled = isLocationServicesEnabled;
30
+
31
+ const isLocationPermissionGranted = () => {
32
+ return (0, _helpers.isValidPlatform)(_OkHiNativeModule.OkHiNativeModule.isLocationPermissionGranted);
33
+ };
34
+
35
+ exports.isLocationPermissionGranted = isLocationPermissionGranted;
36
+
37
+ const isBackgroundLocationPermissionGrantedAndroid = async () => {
38
+ const sdkVersion = await _OkHiNativeModule.OkHiNativeModule.getSystemVersion();
39
+
40
+ if (sdkVersion < 23) {
41
+ return true;
42
+ }
43
+
44
+ if (sdkVersion < 29) {
45
+ return await isLocationPermissionGranted();
46
+ }
47
+
48
+ if (typeof _reactNative.PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION !== 'undefined') {
49
+ const hasPermission = await _reactNative.PermissionsAndroid.check(_reactNative.PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION);
50
+ return hasPermission;
51
+ }
52
+
53
+ console.warn(`PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION is undefined, this is an issue with the current version of RN you are running. Please consider upgrading`);
54
+ return false;
55
+ };
56
+
57
+ const isBackgroundLocationPermissionGrantedIOS = () => {
58
+ return _OkHiNativeModule.OkHiNativeModule.isBackgroundLocationPermissionGranted();
59
+ };
60
+ /**
61
+ * Checks whether background location permission is granted
62
+ * @returns {Promise<boolean>} A promise that resolves to a boolen value indicating whether the permission is granted
63
+ */
64
+
65
+
66
+ const isBackgroundLocationPermissionGranted = () => {
67
+ const fn = _reactNative.Platform.OS === 'android' ? isBackgroundLocationPermissionGrantedAndroid : isBackgroundLocationPermissionGrantedIOS;
68
+ return (0, _helpers.isValidPlatform)(fn);
69
+ };
70
+
71
+ exports.isBackgroundLocationPermissionGranted = isBackgroundLocationPermissionGranted;
72
+
73
+ const requestLocationPermissionAndroid = async () => {
74
+ const status = await _reactNative.PermissionsAndroid.requestMultiple([_reactNative.PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION, _reactNative.PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION]);
75
+ return status['android.permission.ACCESS_FINE_LOCATION'] === 'granted';
76
+ };
77
+
78
+ const requestLocationPermissionIOS = () => {
79
+ return _OkHiNativeModule.OkHiNativeModule.requestLocationPermission();
80
+ };
81
+ /**
82
+ * Requests for when in use location permission
83
+ * @returns {Promise<boolean>} A promise that resolves to a boolen value indicating whether the permission is granted
84
+ */
85
+
86
+
87
+ const requestLocationPermission = async () => {
88
+ const isGranted = await isLocationPermissionGranted();
89
+ if (isGranted) return isGranted;
90
+ return (0, _helpers.errorHandler)(_reactNative.Platform.OS === 'android' ? requestLocationPermissionAndroid : requestLocationPermissionIOS);
91
+ };
92
+
93
+ exports.requestLocationPermission = requestLocationPermission;
94
+
95
+ const requestBackgroundLocationPermissionAndroid = async () => {
96
+ const sdkVersion = await _OkHiNativeModule.OkHiNativeModule.getSystemVersion();
97
+ if (sdkVersion < 23) return true;
98
+
99
+ if (sdkVersion >= 29) {
100
+ const permissions = [_reactNative.PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION];
101
+ const status = await _reactNative.PermissionsAndroid.requestMultiple(permissions);
102
+ return status['android.permission.ACCESS_BACKGROUND_LOCATION'] === 'granted';
103
+ } else {
104
+ return await requestLocationPermissionAndroid();
105
+ }
106
+ };
107
+
108
+ const requestBackgroundLocationPermissionIOS = () => {
109
+ return _OkHiNativeModule.OkHiNativeModule.requestBackgroundLocationPermission();
110
+ };
111
+ /**
112
+ * Requests for background location permission
113
+ * @returns {Promise<boolean>} A promise that resolves to a boolen value indicating whether the permission is granted
114
+ */
115
+
116
+
117
+ const requestBackgroundLocationPermission = async () => {
118
+ const isGranted = await isBackgroundLocationPermissionGranted();
119
+ if (isGranted) return isGranted;
120
+ return (0, _helpers.errorHandler)(_reactNative.Platform.OS === 'android' ? requestBackgroundLocationPermissionAndroid : requestBackgroundLocationPermissionIOS);
121
+ };
122
+ /**
123
+ * Requests the user to enable location services by showing an in app modal on android and opening location settings on iOS
124
+ * @returns {Promise<boolean>} A promise that resolves to either a boolean value on android or null on iOS
125
+ */
126
+
127
+
128
+ exports.requestBackgroundLocationPermission = requestBackgroundLocationPermission;
129
+
130
+ const requestEnableLocationServices = () => {
131
+ return (0, _helpers.isValidPlatform)(_OkHiNativeModule.OkHiNativeModule.requestEnableLocationServices);
132
+ };
133
+ /**
134
+ * Android Only - Checks if Google Play Services is available
135
+ * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service is avaialbe
136
+ */
137
+
138
+
139
+ exports.requestEnableLocationServices = requestEnableLocationServices;
140
+
141
+ const isGooglePlayServicesAvailable = () => {
142
+ return (0, _helpers.isValidPlatform)(_OkHiNativeModule.OkHiNativeModule.isGooglePlayServicesAvailable, 'android');
143
+ };
144
+ /**
145
+ * Android Only - Requests user to enable Google Play Services
146
+ * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service is avaialbe
147
+ */
148
+
149
+
150
+ exports.isGooglePlayServicesAvailable = isGooglePlayServicesAvailable;
151
+
152
+ const requestEnableGooglePlayServices = () => {
153
+ return (0, _helpers.isValidPlatform)(_OkHiNativeModule.OkHiNativeModule.requestEnableGooglePlayServices, 'android');
154
+ };
155
+ /**
156
+ * Returns the system version of the current platform
157
+ * @returns {Promise<boolean>} A promise that resolves either a string on iOS or number on Android
158
+ */
159
+
160
+
161
+ exports.requestEnableGooglePlayServices = requestEnableGooglePlayServices;
162
+
163
+ const getSystemVersion = () => (0, _helpers.isValidPlatform)(_OkHiNativeModule.OkHiNativeModule.getSystemVersion);
164
+ /**
165
+ * Requests location permission from the user. It'll also attempt to activate any disbaled services (Android Only)
166
+ */
167
+
168
+
169
+ exports.getSystemVersion = getSystemVersion;
170
+
171
+ const request = (locationPermissionType, rationale, callback) => {
172
+ const serviceError = new _OkHiException.OkHiException({
173
+ code: _OkHiException.OkHiException.SERVICE_UNAVAILABLE_CODE,
174
+ message: 'Location service is currently not available. Please enable in app settings'
175
+ });
176
+ const googlePlayError = new _OkHiException.OkHiException({
177
+ code: _OkHiException.OkHiException.SERVICE_UNAVAILABLE_CODE,
178
+ message: 'Google Play Services is currently unavailable. Please enable in settings'
179
+ });
180
+
181
+ const handleError = error => {
182
+ callback(null, error);
183
+ };
184
+
185
+ const handleGooglePlayServiceRequest = () => {
186
+ requestEnableGooglePlayServices().then(googlePlayStatus => {
187
+ if (!googlePlayStatus) {
188
+ handleError(googlePlayError);
189
+ } else {
190
+ handleRationaleRequest();
191
+ }
192
+ });
193
+ };
194
+
195
+ const handleRationaleAlert = alertRationale => {
196
+ return new Promise((resolve, _) => {
197
+ _reactNative.Alert.alert(alertRationale.title, alertRationale.text, [{
198
+ text: alertRationale.grantButton ? alertRationale.grantButton.label : 'Grant',
199
+ onPress: () => {
200
+ resolve(true);
201
+ }
202
+ }, {
203
+ text: alertRationale.denyButton ? alertRationale.denyButton.label : 'Deny',
204
+ onPress: () => {
205
+ resolve(false);
206
+ },
207
+ style: 'cancel'
208
+ }], {
209
+ onDismiss: () => {
210
+ resolve(false);
211
+ }
212
+ });
213
+ });
214
+ };
215
+
216
+ const handlePermissionRequest = () => {
217
+ if (_reactNative.Platform.OS === 'ios') {
218
+ _OkHiNativeModule.OkHiNativeEvents.removeAllListeners('onLocationPermissionStatusUpdate');
219
+
220
+ _OkHiNativeModule.OkHiNativeEvents.addListener('onLocationPermissionStatusUpdate', permissionUpdate => {
221
+ callback(permissionUpdate, null);
222
+ });
223
+
224
+ if (locationPermissionType === 'whenInUse') {
225
+ _OkHiNativeModule.OkHiNativeModule.requestLocationPermission();
226
+ } else {
227
+ _OkHiNativeModule.OkHiNativeModule.requestBackgroundLocationPermission();
228
+ }
229
+ } else {
230
+ if (locationPermissionType === 'whenInUse') {
231
+ requestLocationPermissionAndroid().then(whenInUseResult => callback(whenInUseResult ? 'authorizedWhenInUse' : 'denied', null));
232
+ } else {
233
+ requestLocationPermissionAndroid().then(initialWhenInUseResult => {
234
+ if (!initialWhenInUseResult) {
235
+ callback('denied', null);
236
+ } else {
237
+ callback('authorizedWhenInUse', null);
238
+ requestBackgroundLocationPermission().then(alwaysResult => {
239
+ callback(alwaysResult ? 'authorizedAlways' : 'authorizedWhenInUse', null);
240
+ });
241
+ }
242
+ });
243
+ }
244
+ }
245
+ };
246
+
247
+ const handleRationaleRequest = async () => {
248
+ const currentStatus = await retriveLocationPermissionStatus();
249
+ let showRationale = true;
250
+
251
+ if (locationPermissionType === 'whenInUse' && (currentStatus === 'authorizedWhenInUse' || currentStatus === 'authorizedAlways')) {
252
+ showRationale = false;
253
+ }
254
+
255
+ if (locationPermissionType === 'always' && currentStatus === 'authorizedAlways') {
256
+ showRationale = false;
257
+ }
258
+
259
+ if (rationale && showRationale) {
260
+ const result = await handleRationaleAlert(rationale);
261
+
262
+ if (!result) {
263
+ callback('rationaleDissmissed', null);
264
+ } else {
265
+ handlePermissionRequest();
266
+ }
267
+ } else {
268
+ handlePermissionRequest();
269
+ }
270
+ };
271
+
272
+ isLocationServicesEnabled().then(serviceStatus => {
273
+ if (!serviceStatus && _reactNative.Platform.OS === 'ios') {
274
+ handleError(serviceError);
275
+ } else if (!serviceStatus && _reactNative.Platform.OS === 'android') {
276
+ requestEnableLocationServices().then(enableResult => {
277
+ if (!enableResult) {
278
+ handleError(serviceError);
279
+ } else {
280
+ handleGooglePlayServiceRequest();
281
+ }
282
+ }).catch(handleError);
283
+ } else {
284
+ if (_reactNative.Platform.OS === 'ios') {
285
+ handleRationaleRequest();
286
+ } else {
287
+ handleGooglePlayServiceRequest();
288
+ }
289
+ }
290
+ }).catch(handleError);
291
+ };
292
+ /**
293
+ * Open the device's app settings.
294
+ */
295
+
296
+
297
+ exports.request = request;
298
+
299
+ const openAppSettings = () => {
300
+ _OkHiNativeModule.OkHiNativeModule.openAppSettings();
301
+ };
302
+ /**
303
+ * Retrives the location permission status from the device
304
+ */
305
+
306
+
307
+ exports.openAppSettings = openAppSettings;
308
+
309
+ const retriveLocationPermissionStatus = async () => {
310
+ if (_reactNative.Platform.OS === 'ios') {
311
+ return _OkHiNativeModule.OkHiNativeModule.retriveLocationPermissionStatus();
312
+ }
313
+
314
+ const alwaysPerm = await isBackgroundLocationPermissionGranted();
315
+
316
+ if (alwaysPerm) {
317
+ return 'authorizedAlways';
318
+ }
319
+
320
+ const whenInUsePerm = await isLocationPermissionGranted();
321
+ return whenInUsePerm ? 'authorizedWhenInUse' : 'denied';
322
+ };
323
+ /**
324
+ * Requests tracking authorization from the user. iOS only, iOS version >= 14
325
+ * Read more: https://developer.apple.com/app-store/user-privacy-and-data-use/
326
+ */
327
+
328
+
329
+ exports.retriveLocationPermissionStatus = retriveLocationPermissionStatus;
330
+
331
+ const requestTrackingAuthorization = async () => {
332
+ return (0, _helpers.isValidPlatform)(async () => {
333
+ const result = await _OkHiNativeModule.OkHiNativeModule.requestTrackingAuthorization();
334
+ return result;
335
+ }, 'ios');
336
+ };
337
+ /**
338
+ * Checks whether current device can open "Protected Apps Settings" available in Transsion Group android devices such as Infinix and Tecno
339
+ * When your application is included in protected apps, verification processes are less likely to be terminated by the OS. Increasing rate of users being verified.
340
+ */
341
+
342
+
343
+ exports.requestTrackingAuthorization = requestTrackingAuthorization;
344
+
345
+ const canOpenProtectedAppsSettings = () => {
346
+ return (0, _helpers.isValidPlatform)(async () => {
347
+ const result = await _OkHiNativeModule.OkHiNativeModule.canOpenProtectedAppsSettings();
348
+ return result;
349
+ }, 'android');
350
+ };
351
+ /**
352
+ * Opens "Protected Apps Settings" available in Transsion Group android devices such as Infinix and Tecno
353
+ * When your application is included in protected apps, verification processes are less likely to be terminated by the OS. Increasing rate of users being verified.
354
+ */
355
+
356
+
357
+ exports.canOpenProtectedAppsSettings = canOpenProtectedAppsSettings;
358
+
359
+ const openProtectedAppsSettings = () => {
360
+ return (0, _helpers.isValidPlatform)(async () => {
361
+ const result = await _OkHiNativeModule.OkHiNativeModule.openProtectedAppsSettings();
362
+ return result;
363
+ }, 'android');
364
+ };
365
+
366
+ exports.openProtectedAppsSettings = openProtectedAppsSettings;
367
+ //# sourceMappingURL=Helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["isLocationServicesEnabled","isValidPlatform","OkHiNativeModule","isLocationPermissionGranted","isBackgroundLocationPermissionGrantedAndroid","sdkVersion","getSystemVersion","PermissionsAndroid","PERMISSIONS","ACCESS_BACKGROUND_LOCATION","hasPermission","check","console","warn","isBackgroundLocationPermissionGrantedIOS","isBackgroundLocationPermissionGranted","fn","Platform","OS","requestLocationPermissionAndroid","status","requestMultiple","ACCESS_FINE_LOCATION","ACCESS_COARSE_LOCATION","requestLocationPermissionIOS","requestLocationPermission","isGranted","errorHandler","requestBackgroundLocationPermissionAndroid","permissions","requestBackgroundLocationPermissionIOS","requestBackgroundLocationPermission","requestEnableLocationServices","isGooglePlayServicesAvailable","requestEnableGooglePlayServices","request","locationPermissionType","rationale","callback","serviceError","OkHiException","code","SERVICE_UNAVAILABLE_CODE","message","googlePlayError","handleError","error","handleGooglePlayServiceRequest","then","googlePlayStatus","handleRationaleRequest","handleRationaleAlert","alertRationale","Promise","resolve","_","Alert","alert","title","text","grantButton","label","onPress","denyButton","style","onDismiss","handlePermissionRequest","OkHiNativeEvents","removeAllListeners","addListener","permissionUpdate","whenInUseResult","initialWhenInUseResult","alwaysResult","currentStatus","retriveLocationPermissionStatus","showRationale","result","serviceStatus","enableResult","catch","openAppSettings","alwaysPerm","whenInUsePerm","requestTrackingAuthorization","canOpenProtectedAppsSettings","openProtectedAppsSettings"],"sources":["Helpers.ts"],"sourcesContent":["import { OkHiNativeModule, OkHiNativeEvents } from '../OkHiNativeModule';\nimport { Alert, Permission, PermissionsAndroid, Platform } from 'react-native';\nimport { errorHandler, isValidPlatform } from './_helpers';\nimport type {\n LocationPermissionCallback,\n LocationPermissionStatus,\n LocationRequestPermissionType,\n} from './types';\nimport { OkHiException } from './OkHiException';\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 if (\n typeof PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION !==\n 'undefined'\n ) {\n const hasPermission = await PermissionsAndroid.check(\n PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION as Permission\n );\n return hasPermission;\n }\n console.warn(\n `PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION is undefined, this is an issue with the current version of RN you are running. Please consider upgrading`\n );\n return false;\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 as Permission,\n PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION as Permission,\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\n/**\n * Requests location permission from the user. It'll also attempt to activate any disbaled services (Android Only)\n */\nexport const request = (\n locationPermissionType: LocationRequestPermissionType,\n rationale: {\n title: string;\n text: string;\n successButton?: { label: string };\n denyButton?: { label: string };\n } | null,\n callback: LocationPermissionCallback\n) => {\n const serviceError = new OkHiException({\n code: OkHiException.SERVICE_UNAVAILABLE_CODE,\n message:\n 'Location service is currently not available. Please enable in app settings',\n });\n\n const googlePlayError = new OkHiException({\n code: OkHiException.SERVICE_UNAVAILABLE_CODE,\n message:\n 'Google Play Services is currently unavailable. Please enable in settings',\n });\n\n const handleError = (error: OkHiException) => {\n callback(null, error);\n };\n\n const handleGooglePlayServiceRequest = () => {\n requestEnableGooglePlayServices().then((googlePlayStatus) => {\n if (!googlePlayStatus) {\n handleError(googlePlayError);\n } else {\n handleRationaleRequest();\n }\n });\n };\n\n const handleRationaleAlert = (alertRationale: {\n title: string;\n text: string;\n grantButton?: { label: string };\n denyButton?: { label: string };\n }) => {\n return new Promise((resolve, _) => {\n Alert.alert(\n alertRationale.title,\n alertRationale.text,\n [\n {\n text: alertRationale.grantButton\n ? alertRationale.grantButton.label\n : 'Grant',\n onPress: () => {\n resolve(true);\n },\n },\n {\n text: alertRationale.denyButton\n ? alertRationale.denyButton.label\n : 'Deny',\n onPress: () => {\n resolve(false);\n },\n style: 'cancel',\n },\n ],\n {\n onDismiss: () => {\n resolve(false);\n },\n }\n );\n });\n };\n\n const handlePermissionRequest = () => {\n if (Platform.OS === 'ios') {\n OkHiNativeEvents.removeAllListeners('onLocationPermissionStatusUpdate');\n OkHiNativeEvents.addListener(\n 'onLocationPermissionStatusUpdate',\n (permissionUpdate) => {\n callback(permissionUpdate, null);\n }\n );\n if (locationPermissionType === 'whenInUse') {\n OkHiNativeModule.requestLocationPermission();\n } else {\n OkHiNativeModule.requestBackgroundLocationPermission();\n }\n } else {\n if (locationPermissionType === 'whenInUse') {\n requestLocationPermissionAndroid().then((whenInUseResult) =>\n callback(whenInUseResult ? 'authorizedWhenInUse' : 'denied', null)\n );\n } else {\n requestLocationPermissionAndroid().then((initialWhenInUseResult) => {\n if (!initialWhenInUseResult) {\n callback('denied', null);\n } else {\n callback('authorizedWhenInUse', null);\n requestBackgroundLocationPermission().then((alwaysResult) => {\n callback(\n alwaysResult ? 'authorizedAlways' : 'authorizedWhenInUse',\n null\n );\n });\n }\n });\n }\n }\n };\n\n const handleRationaleRequest = async () => {\n const currentStatus = await retriveLocationPermissionStatus();\n let showRationale = true;\n if (\n locationPermissionType === 'whenInUse' &&\n (currentStatus === 'authorizedWhenInUse' ||\n currentStatus === 'authorizedAlways')\n ) {\n showRationale = false;\n }\n if (\n locationPermissionType === 'always' &&\n currentStatus === 'authorizedAlways'\n ) {\n showRationale = false;\n }\n if (rationale && showRationale) {\n const result = await handleRationaleAlert(rationale);\n if (!result) {\n callback('rationaleDissmissed', null);\n } else {\n handlePermissionRequest();\n }\n } else {\n handlePermissionRequest();\n }\n };\n\n isLocationServicesEnabled()\n .then((serviceStatus) => {\n if (!serviceStatus && Platform.OS === 'ios') {\n handleError(serviceError);\n } else if (!serviceStatus && Platform.OS === 'android') {\n requestEnableLocationServices()\n .then((enableResult) => {\n if (!enableResult) {\n handleError(serviceError);\n } else {\n handleGooglePlayServiceRequest();\n }\n })\n .catch(handleError);\n } else {\n if (Platform.OS === 'ios') {\n handleRationaleRequest();\n } else {\n handleGooglePlayServiceRequest();\n }\n }\n })\n .catch(handleError);\n};\n\n/**\n * Open the device's app settings.\n */\nexport const openAppSettings = () => {\n OkHiNativeModule.openAppSettings();\n};\n\n/**\n * Retrives the location permission status from the device\n */\nexport const retriveLocationPermissionStatus =\n async (): Promise<LocationPermissionStatus> => {\n if (Platform.OS === 'ios') {\n return OkHiNativeModule.retriveLocationPermissionStatus() as Promise<LocationPermissionStatus>;\n }\n const alwaysPerm = await isBackgroundLocationPermissionGranted();\n if (alwaysPerm) {\n return 'authorizedAlways';\n }\n const whenInUsePerm = await isLocationPermissionGranted();\n return whenInUsePerm ? 'authorizedWhenInUse' : 'denied';\n };\n\n/**\n * Requests tracking authorization from the user. iOS only, iOS version >= 14\n * Read more: https://developer.apple.com/app-store/user-privacy-and-data-use/\n */\nexport const requestTrackingAuthorization = async (): Promise<\n string | null\n> => {\n return isValidPlatform(async () => {\n const result = await OkHiNativeModule.requestTrackingAuthorization();\n return result;\n }, 'ios');\n};\n\n/**\n * Checks whether current device can open \"Protected Apps Settings\" available in Transsion Group android devices such as Infinix and Tecno\n * When your application is included in protected apps, verification processes are less likely to be terminated by the OS. Increasing rate of users being verified.\n */\nexport const canOpenProtectedAppsSettings = (): Promise<boolean> => {\n return isValidPlatform(async () => {\n const result = await OkHiNativeModule.canOpenProtectedAppsSettings();\n return result;\n }, 'android');\n};\n\n/**\n * Opens \"Protected Apps Settings\" available in Transsion Group android devices such as Infinix and Tecno\n * When your application is included in protected apps, verification processes are less likely to be terminated by the OS. Increasing rate of users being verified.\n */\nexport const openProtectedAppsSettings = (): Promise<boolean> => {\n return isValidPlatform(async () => {\n const result = await OkHiNative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;;;;;AACO,MAAMQ,4BAA4B,GAAG,MAAwB;EAClE,OAAO,IAAApF,wBAAA,EAAgB,YAAY;IACjC,MAAM4E,MAAM,GAAG,MAAM3E,kCAAA,CAAiBmF,4BAAjB,EAArB;IACA,OAAOR,MAAP;EACD,CAHM,EAGJ,SAHI,CAAP;AAID,CALM;AAOP;AACA;AACA;AACA;;;;;AACO,MAAMS,yBAAyB,GAAG,MAAwB;EAC/D,OAAO,IAAArF,wBAAA,EAAgB,YAAY;IACjC,MAAM4E,MAAM,GAAG,MAAM3E,kCAAA,CAAiBoF,yBAAjB,EAArB;IACA,OAAOT,MAAP;EACD,CAHM,EAGJ,SAHI,CAAP;AAID,CALM"}
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.OkHiAuth = void 0;
7
+
8
+ var _axios = _interopRequireDefault(require("axios"));
9
+
10
+ var _OkHiMode = require("./OkHiMode");
11
+
12
+ var _OkHiException = require("./OkHiException");
13
+
14
+ var _ = require("./");
15
+
16
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
+
18
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
19
+
20
+ /**
21
+ * @ignore
22
+ */
23
+ class OkHiAuth {
24
+ constructor() {
25
+ _defineProperty(this, "API_VERSION", 'v5');
26
+
27
+ _defineProperty(this, "ANONYMOUS_SIGN_IN_ENDPOINT", '/auth/anonymous-signin');
28
+
29
+ _defineProperty(this, "DEV_BASE_URL", `https://dev-api.okhi.io/${this.API_VERSION}` + this.ANONYMOUS_SIGN_IN_ENDPOINT);
30
+
31
+ _defineProperty(this, "SANDBOX_BASE_URL", `https://sandbox-api.okhi.io/${this.API_VERSION}` + this.ANONYMOUS_SIGN_IN_ENDPOINT);
32
+
33
+ _defineProperty(this, "PROD_BASE_URL", `https://api.okhi.io/${this.API_VERSION}` + this.ANONYMOUS_SIGN_IN_ENDPOINT);
34
+
35
+ _defineProperty(this, "config", null);
36
+ }
37
+
38
+ anonymousSignInWithPhoneNumber(phone, scopes, config) {
39
+ this.config = config;
40
+ return this.anonymousSignIn({
41
+ scopes,
42
+ phone
43
+ });
44
+ }
45
+
46
+ anonymousSignInWithUserId(userId, scopes) {
47
+ return this.anonymousSignIn({
48
+ scopes,
49
+ user_id: userId
50
+ });
51
+ }
52
+
53
+ async anonymousSignIn(payload) {
54
+ return new Promise(async (resolve, reject) => {
55
+ try {
56
+ const config = this.config || (await (0, _.getApplicationConfiguration)());
57
+
58
+ if (config === null || !config.auth || !config.auth.token) {
59
+ reject(new _OkHiException.OkHiException({
60
+ code: _OkHiException.OkHiException.UNAUTHORIZED_CODE,
61
+ message: _OkHiException.OkHiException.UNAUTHORIZED_MESSAGE
62
+ }));
63
+ } else {
64
+ const {
65
+ auth,
66
+ context
67
+ } = config;
68
+ let url = this.SANDBOX_BASE_URL;
69
+
70
+ if ((context === null || context === void 0 ? void 0 : context.mode) === 'dev') {
71
+ url = this.DEV_BASE_URL;
72
+ } else if ((context === null || context === void 0 ? void 0 : context.mode) === _OkHiMode.OkHiMode.PROD) {
73
+ url = this.PROD_BASE_URL;
74
+ } else {
75
+ url = this.SANDBOX_BASE_URL;
76
+ }
77
+
78
+ const headers = {
79
+ Authorization: auth.token
80
+ };
81
+ const {
82
+ data
83
+ } = await _axios.default.post(url, payload, {
84
+ headers
85
+ });
86
+ resolve(data.authorization_token);
87
+ }
88
+ } catch (error) {
89
+ reject(this.parseRequestError(error));
90
+ }
91
+ });
92
+ }
93
+
94
+ parseRequestError(error) {
95
+ if (!error.response) {
96
+ return new _OkHiException.OkHiException({
97
+ code: _OkHiException.OkHiException.NETWORK_ERROR_CODE,
98
+ message: _OkHiException.OkHiException.NETWORK_ERROR_MESSAGE
99
+ });
100
+ }
101
+
102
+ switch (error.response.status) {
103
+ case 400:
104
+ return new _OkHiException.OkHiException({
105
+ code: _OkHiException.OkHiException.INVALID_PHONE_CODE,
106
+ message: _OkHiException.OkHiException.INVALID_PHONE_MESSAGE
107
+ });
108
+
109
+ case 401:
110
+ return new _OkHiException.OkHiException({
111
+ code: _OkHiException.OkHiException.UNAUTHORIZED_CODE,
112
+ message: _OkHiException.OkHiException.UNAUTHORIZED_MESSAGE
113
+ });
114
+
115
+ default:
116
+ return new _OkHiException.OkHiException({
117
+ code: _OkHiException.OkHiException.UNKNOWN_ERROR_CODE,
118
+ message: error.message || _OkHiException.OkHiException.UNKNOWN_ERROR_MESSAGE
119
+ });
120
+ }
121
+ }
122
+
123
+ }
124
+
125
+ exports.OkHiAuth = OkHiAuth;
126
+ //# sourceMappingURL=OkHiAuth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["OkHiAuth","API_VERSION","ANONYMOUS_SIGN_IN_ENDPOINT","anonymousSignInWithPhoneNumber","phone","scopes","config","anonymousSignIn","anonymousSignInWithUserId","userId","user_id","payload","Promise","resolve","reject","getApplicationConfiguration","auth","token","OkHiException","code","UNAUTHORIZED_CODE","message","UNAUTHORIZED_MESSAGE","context","url","SANDBOX_BASE_URL","mode","DEV_BASE_URL","OkHiMode","PROD","PROD_BASE_URL","headers","Authorization","data","axios","post","authorization_token","error","parseRequestError","response","NETWORK_ERROR_CODE","NETWORK_ERROR_MESSAGE","status","INVALID_PHONE_CODE","INVALID_PHONE_MESSAGE","UNKNOWN_ERROR_CODE","UNKNOWN_ERROR_MESSAGE"],"sources":["OkHiAuth.ts"],"sourcesContent":["import axios from 'axios';\nimport { OkHiMode } from './OkHiMode';\nimport { OkHiException } from './OkHiException';\nimport type { AuthApplicationConfig, OkHiAccessScope } from './_types';\nimport { getApplicationConfiguration } from './';\n\n/**\n * @ignore\n */\nexport class OkHiAuth {\n private readonly API_VERSION = 'v5';\n private readonly ANONYMOUS_SIGN_IN_ENDPOINT = '/auth/anonymous-signin';\n private readonly DEV_BASE_URL =\n `https://dev-api.okhi.io/${this.API_VERSION}` +\n this.ANONYMOUS_SIGN_IN_ENDPOINT;\n private readonly SANDBOX_BASE_URL =\n `https://sandbox-api.okhi.io/${this.API_VERSION}` +\n this.ANONYMOUS_SIGN_IN_ENDPOINT;\n private readonly PROD_BASE_URL =\n `https://api.okhi.io/${this.API_VERSION}` + this.ANONYMOUS_SIGN_IN_ENDPOINT;\n private config: AuthApplicationConfig | null = null;\n\n anonymousSignInWithPhoneNumber(\n phone: string,\n scopes: Array<OkHiAccessScope>,\n config: AuthApplicationConfig\n ) {\n this.config = config;\n return this.anonymousSignIn({\n scopes,\n phone,\n });\n }\n\n protected anonymousSignInWithUserId(\n userId: string,\n scopes: Array<OkHiAccessScope>\n ) {\n return this.anonymousSignIn({\n scopes,\n user_id: userId,\n });\n }\n\n private async anonymousSignIn(payload: {\n scopes: Array<OkHiAccessScope>;\n [key: string]: any;\n }): Promise<string> {\n return new Promise(async (resolve, reject) => {\n try {\n const config = this.config || (await getApplicationConfiguration());\n if (config === null || !config.auth || !config.auth.token) {\n reject(\n new OkHiException({\n code: OkHiException.UNAUTHORIZED_CODE,\n message: OkHiException.UNAUTHORIZED_MESSAGE,\n })\n );\n } else {\n const { auth, context } = config;\n let url = this.SANDBOX_BASE_URL;\n if (context?.mode === ('dev' as any)) {\n url = this.DEV_BASE_URL;\n } else if (context?.mode === OkHiMode.PROD) {\n url = this.PROD_BASE_URL;\n } else {\n url = this.SANDBOX_BASE_URL;\n }\n const headers = { Authorization: auth.token };\n const { data } = await axios.post(url, payload, {\n headers,\n });\n resolve(data.authorization_token);\n }\n } catch (error) {\n reject(this.parseRequestError(error));\n }\n });\n }\n\n private parseRequestError(error: any) {\n if (!error.response) {\n return new OkHiException({\n code: OkHiException.NETWORK_ERROR_CODE,\n message: OkHiException.NETWORK_ERROR_MESSAGE,\n });\n }\n switch (error.response.status) {\n case 400:\n return new OkHiException({\n code: OkHiException.INVALID_PHONE_CODE,\n message: OkHiException.INVALID_PHONE_MESSAGE,\n });\n case 401:\n return new OkHiException({\n code: OkHiException.UNAUTHORIZED_CODE,\n message: OkHiException.UNAUTHORIZED_MESSAGE,\n });\n default:\n return new OkHiException({\n code: OkHiException.UNKNOWN_ERROR_CODE,\n message: error.message || OkHiException.UNKNOWN_ERROR_MESSAGE,\n });\n }\n }\n}\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAEA;;;;;;AAEA;AACA;AACA;AACO,MAAMA,QAAN,CAAe;EAAA;IAAA,qCACW,IADX;;IAAA,oDAE0B,wBAF1B;;IAAA,sCAIjB,2BAA0B,KAAKC,WAAY,EAA5C,GACA,KAAKC,0BALa;;IAAA,0CAOjB,+BAA8B,KAAKD,WAAY,EAAhD,GACA,KAAKC,0BARa;;IAAA,uCAUjB,uBAAsB,KAAKD,WAAY,EAAxC,GAA4C,KAAKC,0BAV/B;;IAAA,gCAW2B,IAX3B;EAAA;;EAapBC,8BAA8B,CAC5BC,KAD4B,EAE5BC,MAF4B,EAG5BC,MAH4B,EAI5B;IACA,KAAKA,MAAL,GAAcA,MAAd;IACA,OAAO,KAAKC,eAAL,CAAqB;MAC1BF,MAD0B;MAE1BD;IAF0B,CAArB,CAAP;EAID;;EAESI,yBAAyB,CACjCC,MADiC,EAEjCJ,MAFiC,EAGjC;IACA,OAAO,KAAKE,eAAL,CAAqB;MAC1BF,MAD0B;MAE1BK,OAAO,EAAED;IAFiB,CAArB,CAAP;EAID;;EAE4B,MAAfF,eAAe,CAACI,OAAD,EAGT;IAClB,OAAO,IAAIC,OAAJ,CAAY,OAAOC,OAAP,EAAgBC,MAAhB,KAA2B;MAC5C,IAAI;QACF,MAAMR,MAAM,GAAG,KAAKA,MAAL,KAAgB,MAAM,IAAAS,6BAAA,GAAtB,CAAf;;QACA,IAAIT,MAAM,KAAK,IAAX,IAAmB,CAACA,MAAM,CAACU,IAA3B,IAAmC,CAACV,MAAM,CAACU,IAAP,CAAYC,KAApD,EAA2D;UACzDH,MAAM,CACJ,IAAII,4BAAJ,CAAkB;YAChBC,I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