react-native-okhi 1.2.32-beta.6 → 2.0.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.
- package/README.md +156 -16
- package/ReactNativeOkhi.podspec +1 -1
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/okhi/OkhiModule.kt +0 -4
- package/ios/OkHiWrapper.swift +1 -5
- package/ios/Okhi.mm +0 -4
- package/lib/commonjs/NativeOkhi.js.map +1 -1
- package/lib/commonjs/index.js +290 -34
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/types.js +390 -0
- package/lib/commonjs/types.js.map +1 -1
- package/lib/module/NativeOkhi.js.map +1 -1
- package/lib/module/index.js +261 -33
- package/lib/module/index.js.map +1 -1
- package/lib/module/types.js +385 -0
- package/lib/module/types.js.map +1 -1
- package/lib/typescript/commonjs/src/NativeOkhi.d.ts +0 -1
- package/lib/typescript/commonjs/src/NativeOkhi.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/index.d.ts +248 -2
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types.d.ts +540 -4
- package/lib/typescript/commonjs/src/types.d.ts.map +1 -1
- package/lib/typescript/module/src/NativeOkhi.d.ts +0 -1
- package/lib/typescript/module/src/NativeOkhi.d.ts.map +1 -1
- package/lib/typescript/module/src/index.d.ts +248 -2
- package/lib/typescript/module/src/index.d.ts.map +1 -1
- package/lib/typescript/module/src/types.d.ts +540 -4
- package/lib/typescript/module/src/types.d.ts.map +1 -1
- package/package.json +4 -2
- package/src/NativeOkhi.ts +0 -1
- package/src/index.tsx +271 -33
- package/src/types.ts +655 -5
package/README.md
CHANGED
|
@@ -1,37 +1,177 @@
|
|
|
1
|
+
<div align="left">
|
|
2
|
+
|
|
1
3
|
# react-native-okhi
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
[](https://www.npmjs.com/package/react-native-okhi)
|
|
6
|
+
[](https://github.com/OkHi/react-native-okhi/blob/master/LICENSE)
|
|
7
|
+
[](#requirements)
|
|
8
|
+
[](https://github.com/OkHi/react-native-okhi/actions/workflows/ci.yml)
|
|
9
|
+
|
|
10
|
+
</div>
|
|
4
11
|
|
|
5
|
-
##
|
|
12
|
+
## Quick Start
|
|
6
13
|
|
|
14
|
+
### 1. Install
|
|
7
15
|
|
|
8
|
-
```
|
|
16
|
+
```bash
|
|
9
17
|
npm install react-native-okhi
|
|
18
|
+
# or
|
|
19
|
+
yarn add react-native-okhi
|
|
10
20
|
```
|
|
11
21
|
|
|
22
|
+
### 2. Configure native projects
|
|
12
23
|
|
|
13
|
-
|
|
24
|
+
<details>
|
|
25
|
+
<summary><b>iOS Setup</b></summary>
|
|
14
26
|
|
|
27
|
+
Install pods:
|
|
15
28
|
|
|
16
|
-
```
|
|
17
|
-
|
|
29
|
+
```bash
|
|
30
|
+
cd ios && pod install && cd ..
|
|
31
|
+
```
|
|
18
32
|
|
|
19
|
-
|
|
33
|
+
Add to `Info.plist`:
|
|
20
34
|
|
|
21
|
-
|
|
35
|
+
```xml
|
|
36
|
+
<key>NSLocationWhenInUseUsageDescription</key>
|
|
37
|
+
<string>Grant to enable creating addresses at your current location.</string>
|
|
38
|
+
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
|
|
39
|
+
<string>Grant to enable creating and verifying your addresses.</string>
|
|
22
40
|
```
|
|
23
41
|
|
|
42
|
+
Enable Background Modes in Xcode → Signing & Capabilities:
|
|
24
43
|
|
|
25
|
-
|
|
44
|
+
- ✅ Location updates
|
|
45
|
+
- ✅ Background fetch
|
|
26
46
|
|
|
27
|
-
|
|
28
|
-
- [Sending a pull request](CONTRIBUTING.md#sending-a-pull-request)
|
|
29
|
-
- [Code of conduct](CODE_OF_CONDUCT.md)
|
|
47
|
+
Add to `AppDelegate.mm`:
|
|
30
48
|
|
|
31
|
-
|
|
49
|
+
```objc
|
|
50
|
+
@import OkHi;
|
|
51
|
+
|
|
52
|
+
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
|
|
53
|
+
{
|
|
54
|
+
[OK startMonitoring];
|
|
55
|
+
// ... rest of your code
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
If using swift `AppDelegate.swift`:
|
|
60
|
+
|
|
61
|
+
```swift
|
|
62
|
+
import OkHi
|
|
32
63
|
|
|
33
|
-
|
|
64
|
+
@main
|
|
65
|
+
class AppDelegate: UIResponder, UIApplicationDelegate {
|
|
34
66
|
|
|
35
|
-
|
|
67
|
+
func application(
|
|
68
|
+
_ application: UIApplication,
|
|
69
|
+
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
|
|
70
|
+
) -> Bool {
|
|
71
|
+
|
|
72
|
+
OK.startMonitoring() // add this
|
|
73
|
+
return true
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
</details>
|
|
79
|
+
|
|
80
|
+
<details>
|
|
81
|
+
<summary><b>Android Setup</b></summary>
|
|
82
|
+
|
|
83
|
+
Add OkHi Maven repository to `android/build.gradle`:
|
|
84
|
+
|
|
85
|
+
```gradle
|
|
86
|
+
allprojects {
|
|
87
|
+
repositories {
|
|
88
|
+
maven { url "https://repo.okhi.io/artifactory/maven" }
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Add permissions to `AndroidManifest.xml`:
|
|
94
|
+
|
|
95
|
+
```xml
|
|
96
|
+
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
|
97
|
+
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
|
98
|
+
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
|
|
99
|
+
<uses-permission android:name="android.permission.INTERNET" />
|
|
100
|
+
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
|
101
|
+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" />
|
|
102
|
+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" android:foregroundServiceType="location" />
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
</details>
|
|
106
|
+
|
|
107
|
+
<details>
|
|
108
|
+
<summary><b>Expo Setup</b></summary>
|
|
109
|
+
|
|
110
|
+
> **Note:** Requires a development build. This library won't work with Expo Go.
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
npx expo install react-native-okhi@beta
|
|
114
|
+
npx expo prebuild
|
|
115
|
+
npx expo run:ios # or run:android
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
</details>
|
|
119
|
+
|
|
120
|
+
### 3. Verify an address
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
import * as OkHi from 'react-native-okhi';
|
|
124
|
+
|
|
125
|
+
// Step 1
|
|
126
|
+
await OkHi.login({
|
|
127
|
+
auth: {
|
|
128
|
+
branchId: 'YOUR_BRANCH_ID',
|
|
129
|
+
clientKey: 'YOUR_CLIENT_KEY',
|
|
130
|
+
},
|
|
131
|
+
user: {
|
|
132
|
+
firstName: 'John',
|
|
133
|
+
lastName: 'Doe',
|
|
134
|
+
phone: '+254712345678',
|
|
135
|
+
email: 'john@example.com',
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
// Step 2
|
|
140
|
+
const { user, location } = await OkHi.startDigitalAddressVerification();
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Full Example
|
|
144
|
+
|
|
145
|
+
```tsx
|
|
146
|
+
import { Button, Text, View } from 'react-native';
|
|
147
|
+
import * as OkHi from 'react-native-okhi';
|
|
148
|
+
|
|
149
|
+
export default function Dashboard() {
|
|
150
|
+
useEffect(() => {
|
|
151
|
+
OkHi.login({
|
|
152
|
+
auth: { branchId: 'YOUR_BRANCH_ID', clientKey: 'YOUR_CLIENT_KEY' },
|
|
153
|
+
user: {
|
|
154
|
+
firstName: 'John',
|
|
155
|
+
lastName: 'Doe',
|
|
156
|
+
phone: '+254712345678',
|
|
157
|
+
email: 'john@example.com',
|
|
158
|
+
},
|
|
159
|
+
}).then(() => console.log('user logged in'));
|
|
160
|
+
}, []);
|
|
161
|
+
|
|
162
|
+
const onButtonPress = async () => {
|
|
163
|
+
const { user, location } = await OkHi.startDigitalAddressVerification();
|
|
164
|
+
console.log(`started verification for: ${location.id}`);
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
return (
|
|
168
|
+
<View style={{ flex: 1, justifyContent: 'center', padding: 20 }}>
|
|
169
|
+
<Button title="Verify Address" onPress={onButtonPress} />
|
|
170
|
+
</View>
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## License
|
|
36
176
|
|
|
37
|
-
|
|
177
|
+
MIT © [OkHi](https://okhi.co)
|
package/ReactNativeOkhi.podspec
CHANGED
package/android/build.gradle
CHANGED
|
@@ -73,7 +73,7 @@ repositories {
|
|
|
73
73
|
def kotlin_version = getExtOrDefault("kotlinVersion")
|
|
74
74
|
|
|
75
75
|
dependencies {
|
|
76
|
-
implementation 'io.okhi.android:okhi:1.0.
|
|
76
|
+
implementation 'io.okhi.android:okhi:1.0.5'
|
|
77
77
|
implementation "com.facebook.react:react-android"
|
|
78
78
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
79
79
|
}
|
|
@@ -50,10 +50,6 @@ class OkhiModule(reactContext: ReactApplicationContext) : NativeOkhiSpec(reactCo
|
|
|
50
50
|
return NAME
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
override fun multiply(a: Double, b: Double): Double {
|
|
54
|
-
return a * b
|
|
55
|
-
}
|
|
56
|
-
|
|
57
53
|
override fun login(credentials: ReadableMap?, callback: Callback?) {
|
|
58
54
|
if (credentials == null) {
|
|
59
55
|
callback?.invoke(null)
|
package/ios/OkHiWrapper.swift
CHANGED
|
@@ -17,10 +17,6 @@ import UserNotifications
|
|
|
17
17
|
okVerify.delegate = self
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
@objc public static func multiply(_ a: Double, _ b: Double) -> NSNumber {
|
|
21
|
-
return NSNumber(value: a * b)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
20
|
@objc public static func login(_ credentials: NSDictionary, callback: @escaping ([String]?) -> Void) {
|
|
25
21
|
// Extract auth dictionary
|
|
26
22
|
guard let authDict = credentials["auth"] as? NSDictionary,
|
|
@@ -54,7 +50,7 @@ import UserNotifications
|
|
|
54
50
|
let auth = OkHiAuth(
|
|
55
51
|
branchId: branchId,
|
|
56
52
|
clientKey: clientKey,
|
|
57
|
-
environment: env
|
|
53
|
+
environment: env,
|
|
58
54
|
appContext: nativeAppContext
|
|
59
55
|
)
|
|
60
56
|
|
package/ios/Okhi.mm
CHANGED
|
@@ -8,10 +8,6 @@
|
|
|
8
8
|
#endif
|
|
9
9
|
|
|
10
10
|
@implementation Okhi
|
|
11
|
-
- (NSNumber *)multiply:(double)a b:(double)b {
|
|
12
|
-
return [OkHiWrapper multiply:a :b];
|
|
13
|
-
}
|
|
14
|
-
|
|
15
11
|
- (void)login:(NSDictionary *)credentials callback:(RCTResponseSenderBlock)callback {
|
|
16
12
|
[OkHiWrapper login:credentials callback:^(NSArray<NSString *> *results) {
|
|
17
13
|
if (callback) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","_default","exports","default","TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativeOkhi.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAAqE,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_default","exports","default","TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativeOkhi.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAAqE,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAkEtDC,gCAAmB,CAACC,YAAY,CAAO,MAAM,CAAC","ignoreList":[]}
|
package/lib/commonjs/index.js
CHANGED
|
@@ -3,6 +3,26 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
login: true,
|
|
8
|
+
startDigitalAddressVerification: true,
|
|
9
|
+
startPhysicalAddressVerification: true,
|
|
10
|
+
startDigitalAndPhysicalAddressVerification: true,
|
|
11
|
+
createAddress: true,
|
|
12
|
+
isLocationServicesEnabled: true,
|
|
13
|
+
canOpenProtectedApps: true,
|
|
14
|
+
getLocationAccuracyLevel: true,
|
|
15
|
+
isBackgroundLocationPermissionGranted: true,
|
|
16
|
+
isCoarseLocationPermissionGranted: true,
|
|
17
|
+
isFineLocationPermissionGranted: true,
|
|
18
|
+
isPlayServicesAvailable: true,
|
|
19
|
+
isPostNotificationPermissionGranted: true,
|
|
20
|
+
openProtectedApps: true,
|
|
21
|
+
requestLocationPermission: true,
|
|
22
|
+
requestBackgroundLocationPermission: true,
|
|
23
|
+
requestEnableLocationServices: true,
|
|
24
|
+
requestPostNotificationPermissions: true
|
|
25
|
+
};
|
|
6
26
|
exports.canOpenProtectedApps = canOpenProtectedApps;
|
|
7
27
|
exports.createAddress = createAddress;
|
|
8
28
|
exports.getLocationAccuracyLevel = getLocationAccuracyLevel;
|
|
@@ -13,7 +33,6 @@ exports.isLocationServicesEnabled = isLocationServicesEnabled;
|
|
|
13
33
|
exports.isPlayServicesAvailable = isPlayServicesAvailable;
|
|
14
34
|
exports.isPostNotificationPermissionGranted = isPostNotificationPermissionGranted;
|
|
15
35
|
exports.login = login;
|
|
16
|
-
exports.multiply = multiply;
|
|
17
36
|
exports.openProtectedApps = openProtectedApps;
|
|
18
37
|
exports.requestBackgroundLocationPermission = requestBackgroundLocationPermission;
|
|
19
38
|
exports.requestEnableLocationServices = requestEnableLocationServices;
|
|
@@ -24,10 +43,92 @@ exports.startDigitalAndPhysicalAddressVerification = startDigitalAndPhysicalAddr
|
|
|
24
43
|
exports.startPhysicalAddressVerification = startPhysicalAddressVerification;
|
|
25
44
|
var _reactNative = require("react-native");
|
|
26
45
|
var _NativeOkhi = _interopRequireDefault(require("./NativeOkhi"));
|
|
46
|
+
var _types = require("./types");
|
|
47
|
+
Object.keys(_types).forEach(function (key) {
|
|
48
|
+
if (key === "default" || key === "__esModule") return;
|
|
49
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
50
|
+
if (key in exports && exports[key] === _types[key]) return;
|
|
51
|
+
Object.defineProperty(exports, key, {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
get: function () {
|
|
54
|
+
return _types[key];
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
});
|
|
27
58
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
59
|
+
/**
|
|
60
|
+
* @packageDocumentation
|
|
61
|
+
* React Native OkHi SDK
|
|
62
|
+
*
|
|
63
|
+
* A comprehensive React Native library for address verification using OkHi's
|
|
64
|
+
* digital and physical verification methods.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* import * as OkHi from 'react-native-okhi';
|
|
69
|
+
*
|
|
70
|
+
* // 1. Login
|
|
71
|
+
* await OkHi.login({
|
|
72
|
+
* auth: { branchId: 'xxx', clientKey: 'xxx' },
|
|
73
|
+
* user: { firstName: 'John', lastName: 'Doe', phone: '+254...', email: '...' },
|
|
74
|
+
* });
|
|
75
|
+
*
|
|
76
|
+
* // 2. Start verification
|
|
77
|
+
* const result = await OkHi.startDigitalAddressVerification();
|
|
78
|
+
* console.log('Verified address:', result.location.formattedAddress);
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Authenticates a user with the OkHi platform.
|
|
84
|
+
*
|
|
85
|
+
* @remarks
|
|
86
|
+
* This must be called before any verification functions. It establishes
|
|
87
|
+
* the user session and validates your API credentials.
|
|
88
|
+
*
|
|
89
|
+
* **When to call login:** The login function should be called once you have
|
|
90
|
+
* an authenticated user in your app. A common place to call login is immediately
|
|
91
|
+
* after the app dashboard is rendered, for example in a banking app after a user
|
|
92
|
+
* successfully signs in.
|
|
93
|
+
*
|
|
94
|
+
* It initializes OkHi and enables your users to resume verification if they
|
|
95
|
+
* switch devices, as well as enables re-verification of previously unknown addresses.
|
|
96
|
+
*
|
|
97
|
+
* The login persists for the duration of the app session.
|
|
98
|
+
*
|
|
99
|
+
* @param credentials - The login configuration containing auth credentials and user info
|
|
100
|
+
* @returns A promise that resolves with an array of permission strings that were granted,
|
|
101
|
+
* or `null` if `withPermissionsRequest` was not enabled
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* import * as OkHi from 'react-native-okhi';
|
|
106
|
+
* import type { OkHiLogin } from 'react-native-okhi';
|
|
107
|
+
*
|
|
108
|
+
* const credentials: OkHiLogin = {
|
|
109
|
+
* auth: {
|
|
110
|
+
* branchId: 'your_branch_id',
|
|
111
|
+
* clientKey: 'your_client_key',
|
|
112
|
+
* },
|
|
113
|
+
* user: {
|
|
114
|
+
* firstName: 'John',
|
|
115
|
+
* lastName: 'Doe',
|
|
116
|
+
* phone: '+254712345678',
|
|
117
|
+
* email: 'john.doe@example.com',
|
|
118
|
+
* },
|
|
119
|
+
* };
|
|
120
|
+
*
|
|
121
|
+
* try {
|
|
122
|
+
* await OkHi.login(credentials);
|
|
123
|
+
* console.log('Login successful');
|
|
124
|
+
* } catch (error) {
|
|
125
|
+
* console.error('Login failed:', error);
|
|
126
|
+
* }
|
|
127
|
+
* ```
|
|
128
|
+
*
|
|
129
|
+
* @see {@link OkHiLogin} - Configuration type
|
|
130
|
+
* @see {@link startDigitalAddressVerification} - Call after login to verify addresses
|
|
131
|
+
*/
|
|
31
132
|
function login(credentials) {
|
|
32
133
|
return new Promise(resolve => {
|
|
33
134
|
_NativeOkhi.default.login(credentials, results => {
|
|
@@ -64,23 +165,70 @@ function processVerificationResponse(response, error, resolve, reject) {
|
|
|
64
165
|
});
|
|
65
166
|
} else if (error != null) {
|
|
66
167
|
const err = error;
|
|
67
|
-
reject(
|
|
68
|
-
code: err.code,
|
|
69
|
-
message: err.message
|
|
70
|
-
});
|
|
168
|
+
reject(_types.OkHiException.fromNativeError(err));
|
|
71
169
|
} else {
|
|
72
|
-
reject(
|
|
73
|
-
code: 'unknown',
|
|
74
|
-
message: 'unable to complete operation - unknown response'
|
|
75
|
-
});
|
|
170
|
+
reject(new _types.OkHiException(_types.OkHiException.UNKNOWN, 'An unknown error occurred'));
|
|
76
171
|
}
|
|
77
172
|
} catch {
|
|
78
|
-
reject(
|
|
79
|
-
code: 'unknown',
|
|
80
|
-
message: 'unable to complete operation - unknown error'
|
|
81
|
-
});
|
|
173
|
+
reject(new _types.OkHiException(_types.OkHiException.UNKNOWN, 'An unknown error occurred'));
|
|
82
174
|
}
|
|
83
175
|
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* @remarks
|
|
179
|
+
* Starts the digital address verification flow.
|
|
180
|
+
*
|
|
181
|
+
* **Prerequisites:**
|
|
182
|
+
* - Must call {@link login} first
|
|
183
|
+
*
|
|
184
|
+
* @param okcollect - Optional configuration for styling and behavior
|
|
185
|
+
* @returns A promise that resolves with the user and location data
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```typescript
|
|
189
|
+
* import * as OkHi from 'react-native-okhi';
|
|
190
|
+
*
|
|
191
|
+
* // Basic usage with defaults
|
|
192
|
+
* const result = await OkHi.startDigitalAddressVerification();
|
|
193
|
+
* console.log('Address:', result.location.formattedAddress);
|
|
194
|
+
* console.log('Location ID:', result.location.id);
|
|
195
|
+
* ```
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```typescript
|
|
199
|
+
* import * as OkHi from 'react-native-okhi';
|
|
200
|
+
* import type { OkCollect } from 'react-native-okhi';
|
|
201
|
+
*
|
|
202
|
+
* // With custom styling
|
|
203
|
+
* const config: OkCollect = {
|
|
204
|
+
* style: {
|
|
205
|
+
* color: '#FF5722',
|
|
206
|
+
* logo: 'https://example.com/logo.png',
|
|
207
|
+
* },
|
|
208
|
+
* configuration: {
|
|
209
|
+
* streetView: true,
|
|
210
|
+
* },
|
|
211
|
+
* };
|
|
212
|
+
*
|
|
213
|
+
* const result = await OkHi.startDigitalAddressVerification(config);
|
|
214
|
+
* ```
|
|
215
|
+
*
|
|
216
|
+
* @example
|
|
217
|
+
* ```typescript
|
|
218
|
+
* import * as OkHi from 'react-native-okhi';
|
|
219
|
+
*
|
|
220
|
+
* // Start verification on previously created address
|
|
221
|
+
* const locationId: string = await fetchLocationIDFromMyDB()
|
|
222
|
+
* const result = await OkHi.startDigitalAddressVerification({
|
|
223
|
+
* locationId: locationId,
|
|
224
|
+
* });
|
|
225
|
+
* ```
|
|
226
|
+
*
|
|
227
|
+
* @see {@link OkCollect} - Configuration options
|
|
228
|
+
* @see {@link OkHiSuccessResponse} - Return type
|
|
229
|
+
* @see {@link startPhysicalAddressVerification} - For physical verification
|
|
230
|
+
* @see {@link startDigitalAndPhysicalAddressVerification} - For combined verification
|
|
231
|
+
*/
|
|
84
232
|
function startDigitalAddressVerification(okcollect) {
|
|
85
233
|
const config = buildConfig(okcollect);
|
|
86
234
|
return new Promise((resolve, reject) => {
|
|
@@ -89,6 +237,44 @@ function startDigitalAddressVerification(okcollect) {
|
|
|
89
237
|
});
|
|
90
238
|
});
|
|
91
239
|
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Starts the physical address verification flow.
|
|
243
|
+
*
|
|
244
|
+
* @remarks
|
|
245
|
+
* Physical verification requires an agent to visit the user's location
|
|
246
|
+
* in person.
|
|
247
|
+
*
|
|
248
|
+
* **Prerequisites:**
|
|
249
|
+
* - Must call {@link login} first
|
|
250
|
+
*
|
|
251
|
+
* @param okcollect - Optional configuration for styling and behavior
|
|
252
|
+
* @returns A promise that resolves with the user and location data
|
|
253
|
+
*
|
|
254
|
+
* @example
|
|
255
|
+
* ```typescript
|
|
256
|
+
* import * as OkHi from 'react-native-okhi';
|
|
257
|
+
*
|
|
258
|
+
* const result = await OkHi.startPhysicalAddressVerification();
|
|
259
|
+
* console.log('Verification requested for:', result.location.formattedAddress);
|
|
260
|
+
* console.log('Location ID for tracking:', result.location.id);
|
|
261
|
+
* ```
|
|
262
|
+
*
|
|
263
|
+
* @example
|
|
264
|
+
* ```typescript
|
|
265
|
+
* import * as OkHi from 'react-native-okhi';
|
|
266
|
+
*
|
|
267
|
+
* // With custom configuration
|
|
268
|
+
* const result = await OkHi.startPhysicalAddressVerification({
|
|
269
|
+
* style: { color: '#2196F3' },
|
|
270
|
+
* });
|
|
271
|
+
* ```
|
|
272
|
+
*
|
|
273
|
+
* @see {@link OkCollect} - Configuration options
|
|
274
|
+
* @see {@link OkHiSuccessResponse} - Return type
|
|
275
|
+
* @see {@link startDigitalAddressVerification} - For instant digital verification
|
|
276
|
+
* @see {@link startDigitalAndPhysicalAddressVerification} - For combined verification
|
|
277
|
+
*/
|
|
92
278
|
function startPhysicalAddressVerification(okcollect) {
|
|
93
279
|
const config = buildConfig(okcollect);
|
|
94
280
|
return new Promise((resolve, reject) => {
|
|
@@ -97,6 +283,48 @@ function startPhysicalAddressVerification(okcollect) {
|
|
|
97
283
|
});
|
|
98
284
|
});
|
|
99
285
|
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Starts both digital and physical address verification flows.
|
|
289
|
+
*
|
|
290
|
+
* @remarks
|
|
291
|
+
* This combines both verification methods for maximum confidence.
|
|
292
|
+
*
|
|
293
|
+
* **Prerequisites:**
|
|
294
|
+
* - Must call {@link login} first
|
|
295
|
+
*
|
|
296
|
+
* @param okcollect - Optional configuration for styling and behavior
|
|
297
|
+
* @returns A promise that resolves with the user and location data
|
|
298
|
+
*
|
|
299
|
+
* @example
|
|
300
|
+
* ```typescript
|
|
301
|
+
* import * as OkHi from 'react-native-okhi';
|
|
302
|
+
*
|
|
303
|
+
* const result = await OkHi.startDigitalAndPhysicalAddressVerification();
|
|
304
|
+
* console.log('Physical + Digital Verification started for:', result.location.id);
|
|
305
|
+
* ```
|
|
306
|
+
*
|
|
307
|
+
* @example
|
|
308
|
+
* ```typescript
|
|
309
|
+
* import * as OkHi from 'react-native-okhi';
|
|
310
|
+
*
|
|
311
|
+
* // With full customization
|
|
312
|
+
* const result = await OkHi.startDigitalAndPhysicalAddressVerification({
|
|
313
|
+
* style: {
|
|
314
|
+
* color: '#4CAF50',
|
|
315
|
+
* logo: 'https://example.com/logo.png',
|
|
316
|
+
* },
|
|
317
|
+
* configuration: {
|
|
318
|
+
* streetView: true,
|
|
319
|
+
* },
|
|
320
|
+
* });
|
|
321
|
+
* ```
|
|
322
|
+
*
|
|
323
|
+
* @see {@link OkCollect} - Configuration options
|
|
324
|
+
* @see {@link OkHiSuccessResponse} - Return type
|
|
325
|
+
* @see {@link startDigitalAddressVerification} - For digital-only verification
|
|
326
|
+
* @see {@link startPhysicalAddressVerification} - For physical-only verification
|
|
327
|
+
*/
|
|
100
328
|
function startDigitalAndPhysicalAddressVerification(okcollect) {
|
|
101
329
|
const config = buildConfig(okcollect);
|
|
102
330
|
return new Promise((resolve, reject) => {
|
|
@@ -105,6 +333,49 @@ function startDigitalAndPhysicalAddressVerification(okcollect) {
|
|
|
105
333
|
});
|
|
106
334
|
});
|
|
107
335
|
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Creates an address without starting verification.
|
|
339
|
+
*
|
|
340
|
+
* @remarks
|
|
341
|
+
* Use this when you want to collect and store an address but defer
|
|
342
|
+
* verification to a later time. The address can
|
|
343
|
+
* be verified later using the returned `locationId`.
|
|
344
|
+
*
|
|
345
|
+
* **Prerequisites:**
|
|
346
|
+
* - Must call {@link login} first
|
|
347
|
+
*
|
|
348
|
+
* @param okcollect - Optional configuration for styling and behavior
|
|
349
|
+
* @returns A promise that resolves with the user and location data
|
|
350
|
+
*
|
|
351
|
+
* @example
|
|
352
|
+
* ```typescript
|
|
353
|
+
* import * as OkHi from 'react-native-okhi';
|
|
354
|
+
*
|
|
355
|
+
* // Create address without verification
|
|
356
|
+
* const result = await OkHi.createAddress();
|
|
357
|
+
* console.log('Address created:', result.location.id);
|
|
358
|
+
*
|
|
359
|
+
* // Save the location ID to verify later
|
|
360
|
+
* const locationId = result.location.id;
|
|
361
|
+
* await saveToDatabase({ locationId: locationId });
|
|
362
|
+
* ```
|
|
363
|
+
*
|
|
364
|
+
* @example
|
|
365
|
+
* ```typescript
|
|
366
|
+
* import * as OkHi from 'react-native-okhi';
|
|
367
|
+
*
|
|
368
|
+
* // Later, verify the saved address
|
|
369
|
+
* const savedLocationId = await fetchLocationIdFromMyDB();
|
|
370
|
+
* const result = await OkHi.startDigitalAddressVerification({
|
|
371
|
+
* locationId: savedLocationId,
|
|
372
|
+
* });
|
|
373
|
+
* ```
|
|
374
|
+
*
|
|
375
|
+
* @see {@link OkCollect} - Configuration options
|
|
376
|
+
* @see {@link OkHiSuccessResponse} - Return type
|
|
377
|
+
* @see {@link startDigitalAddressVerification} - To verify an address
|
|
378
|
+
*/
|
|
108
379
|
function createAddress(okcollect) {
|
|
109
380
|
const config = buildConfig(okcollect);
|
|
110
381
|
return new Promise((resolve, reject) => {
|
|
@@ -118,10 +389,7 @@ function createAddress(okcollect) {
|
|
|
118
389
|
function processBooleanResponse(result, error, resolve, reject) {
|
|
119
390
|
if (error != null) {
|
|
120
391
|
const err = error;
|
|
121
|
-
reject(
|
|
122
|
-
code: err.code,
|
|
123
|
-
message: err.message
|
|
124
|
-
});
|
|
392
|
+
reject(_types.OkHiException.fromNativeError(err));
|
|
125
393
|
} else {
|
|
126
394
|
resolve(result);
|
|
127
395
|
}
|
|
@@ -131,17 +399,11 @@ function processBooleanResponse(result, error, resolve, reject) {
|
|
|
131
399
|
function processStringResponse(result, error, resolve, reject) {
|
|
132
400
|
if (error != null) {
|
|
133
401
|
const err = error;
|
|
134
|
-
reject(
|
|
135
|
-
code: err.code,
|
|
136
|
-
message: err.message
|
|
137
|
-
});
|
|
402
|
+
reject(_types.OkHiException.fromNativeError(err));
|
|
138
403
|
} else {
|
|
139
404
|
resolve(result);
|
|
140
405
|
}
|
|
141
406
|
}
|
|
142
|
-
|
|
143
|
-
// MARK: - Check Helpers
|
|
144
|
-
|
|
145
407
|
function isLocationServicesEnabled() {
|
|
146
408
|
return new Promise((resolve, reject) => {
|
|
147
409
|
_NativeOkhi.default.isLocationServicesEnabled((result, error) => {
|
|
@@ -204,9 +466,6 @@ function openProtectedApps() {
|
|
|
204
466
|
resolve();
|
|
205
467
|
});
|
|
206
468
|
}
|
|
207
|
-
|
|
208
|
-
// MARK: - Request Helpers
|
|
209
|
-
|
|
210
469
|
function requestLocationPermission() {
|
|
211
470
|
return new Promise((resolve, reject) => {
|
|
212
471
|
_NativeOkhi.default.requestLocationPermission((result, error) => {
|
|
@@ -231,10 +490,7 @@ function requestEnableLocationServices() {
|
|
|
231
490
|
function requestPostNotificationPermissions() {
|
|
232
491
|
return new Promise((resolve, reject) => {
|
|
233
492
|
if (_reactNative.Platform.OS === 'ios') {
|
|
234
|
-
reject(
|
|
235
|
-
code: 'unsupported_platform',
|
|
236
|
-
message: 'operation not supported'
|
|
237
|
-
});
|
|
493
|
+
reject(new _types.OkHiException(_types.OkHiException.UNSUPPORTED_DEVICE, 'Notification permission request is not supported on iOS. Use iOS-specific notification APIs.'));
|
|
238
494
|
} else {
|
|
239
495
|
_NativeOkhi.default.requestPostNotificationPermissions((result, error) => {
|
|
240
496
|
processBooleanResponse(result, error, resolve, reject);
|