@socure-inc/docv-react-native 5.2.7 → 5.2.8
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 +259 -72
- package/android/build.gradle +9 -2
- package/android/src/main/java/com/socure/docv/reactnative/SocureDocVReactNativeModule.kt +147 -77
- package/android/src/main/java/com/socure/docv/reactnative/SocureDocVReactNativePackage.kt +21 -7
- package/android/src/oldarch/com/socure/docv/reactnative/NativeSocureDocVReactNativeSpec.kt +17 -0
- package/ios/SocureDocVReactNative-Bridging-Header.h +1 -0
- package/ios/SocureDocVReactNative.mm +68 -0
- package/ios/SocureDocVReactNative.swift +95 -61
- package/lib/commonjs/NativeSocureDocVReactNative.js +9 -0
- package/lib/commonjs/NativeSocureDocVReactNative.js.map +1 -0
- package/lib/commonjs/index.js +20 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/NativeSocureDocVReactNative.js +3 -0
- package/lib/module/NativeSocureDocVReactNative.js.map +1 -0
- package/lib/module/index.js +18 -1
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/NativeSocureDocVReactNative.d.ts +9 -0
- package/lib/typescript/index.d.ts +4 -0
- package/package.json +13 -4
- package/socure-docv-react-native.podspec +2 -3
- package/src/NativeSocureDocVReactNative.ts +16 -0
- package/src/index.ts +34 -4
- package/ios/SocureDocVReactNative.m +0 -10
|
@@ -13,84 +13,127 @@ import com.socure.docv.capturesdk.api.SocureSdk.getResult
|
|
|
13
13
|
import com.socure.docv.capturesdk.api.SocureSdk.initSdk
|
|
14
14
|
import com.socure.docv.capturesdk.common.utils.SocureDocVFailure
|
|
15
15
|
import com.socure.docv.capturesdk.common.utils.SocureDocVSuccess
|
|
16
|
-
import com.socure.docv.capturesdk.common.utils.SocureResult
|
|
17
16
|
|
|
18
17
|
class SocureDocVReactNativeModule(reactContext: ReactApplicationContext) :
|
|
19
|
-
|
|
18
|
+
NativeSocureDocVReactNativeSpec(reactContext), ActivityEventListener {
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
override fun getName(): String {
|
|
27
|
-
return "SocureDocVReactNative"
|
|
20
|
+
companion object {
|
|
21
|
+
const val NAME = "SocureDocVReactNative"
|
|
22
|
+
private const val TAG = "SDLT_RN"
|
|
23
|
+
private const val SOCURE_SDK_REQUEST_CODE = 753
|
|
28
24
|
}
|
|
29
25
|
|
|
26
|
+
// One of these will be set per in-flight session; never both.
|
|
27
|
+
private var pendingPromise: Promise? = null
|
|
28
|
+
private var pendingSuccessCallback: Callback? = null
|
|
29
|
+
private var pendingErrorCallback: Callback? = null
|
|
30
|
+
|
|
31
|
+
override fun getName(): String = NAME
|
|
32
|
+
|
|
33
|
+
// ── Experimental two-step API ────────────────────────────────────────────
|
|
34
|
+
|
|
30
35
|
@OptIn(SocureExperimentalApi::class)
|
|
31
36
|
@ReactMethod
|
|
32
37
|
fun initDocVSdk(verificationToken: String, publicKey: String, useSocureGov: Boolean) {
|
|
33
38
|
Log.d(TAG, "initDocVSdk - init native sdk")
|
|
34
|
-
initSdk(
|
|
35
|
-
SocureDocVContext(verificationToken, publicKey, useSocureGov, null, null)
|
|
36
|
-
)
|
|
39
|
+
initSdk(SocureDocVContext(verificationToken, publicKey, useSocureGov, null, null))
|
|
37
40
|
}
|
|
38
41
|
|
|
42
|
+
|
|
39
43
|
@OptIn(SocureExperimentalApi::class)
|
|
40
44
|
@ReactMethod
|
|
41
45
|
fun launchDocVSdk(onSuccess: Callback, onError: Callback) {
|
|
42
46
|
Log.d(TAG, "launchDocVSdk - launch using experimental api")
|
|
43
|
-
|
|
47
|
+
if (pendingPromise != null || pendingSuccessCallback != null) {
|
|
48
|
+
onError.invoke(buildErrorMap("ERR_ALREADY_IN_PROGRESS", "A DocV session is already in progress", null))
|
|
49
|
+
return
|
|
50
|
+
}
|
|
51
|
+
pendingSuccessCallback = onSuccess
|
|
52
|
+
pendingErrorCallback = onError
|
|
53
|
+
reactApplicationContext.addActivityEventListener(this)
|
|
54
|
+
SocureSdk.setSource(REACT_NATIVE)
|
|
44
55
|
val activity = reactApplicationContext.currentActivity
|
|
45
56
|
if (activity == null) {
|
|
46
57
|
Log.e(TAG, "Aborting since app activity object is null")
|
|
58
|
+
reactApplicationContext.removeActivityEventListener(this)
|
|
59
|
+
onError.invoke(buildErrorMap("ERR_NO_ACTIVITY", "App activity is null", null))
|
|
60
|
+
pendingSuccessCallback = null
|
|
61
|
+
pendingErrorCallback = null
|
|
47
62
|
return
|
|
48
63
|
}
|
|
49
|
-
activity.
|
|
50
|
-
startActivityForResult(SocureSdk.getIntent(this), SOCURE_SDK_REQUEST_CODE)
|
|
51
|
-
}
|
|
64
|
+
activity.startActivityForResult(SocureSdk.getIntent(activity), SOCURE_SDK_REQUEST_CODE)
|
|
52
65
|
}
|
|
53
66
|
|
|
67
|
+
// ── Callback-based API (legacy, preserved for easy migration) ────────────
|
|
68
|
+
|
|
54
69
|
@ReactMethod
|
|
55
70
|
fun launchSocureDocV(
|
|
56
|
-
|
|
71
|
+
docVTransactionToken: String,
|
|
57
72
|
publicKey: String,
|
|
58
73
|
useSocureGov: Boolean,
|
|
59
74
|
onSuccess: Callback,
|
|
60
75
|
onError: Callback
|
|
61
76
|
) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
val activity = reactApplicationContext.currentActivity
|
|
65
|
-
if (activity == null) {
|
|
66
|
-
Log.e(TAG, "Aborting since app activity object is null")
|
|
77
|
+
if (pendingPromise != null || pendingSuccessCallback != null) {
|
|
78
|
+
onError.invoke(buildErrorMap("ERR_ALREADY_IN_PROGRESS", "A DocV session is already in progress", null))
|
|
67
79
|
return
|
|
68
80
|
}
|
|
81
|
+
Log.d(TAG, "launchSocureDocV (Callback) - launch Socure SDK")
|
|
82
|
+
pendingSuccessCallback = onSuccess
|
|
83
|
+
pendingErrorCallback = onError
|
|
84
|
+
startSdk(docVTransactionToken, publicKey, useSocureGov) {
|
|
85
|
+
onError.invoke(buildErrorMap("ERR_NO_ACTIVITY", "App activity is null", null))
|
|
86
|
+
pendingSuccessCallback = null
|
|
87
|
+
pendingErrorCallback = null
|
|
88
|
+
}
|
|
89
|
+
}
|
|
69
90
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
91
|
+
// ── Promise-based API (new) ───────────────────────────────────────────────
|
|
92
|
+
|
|
93
|
+
override fun launchSocureDocVWithPromise(
|
|
94
|
+
docVTransactionToken: String,
|
|
95
|
+
publicKey: String,
|
|
96
|
+
useSocureGov: Boolean,
|
|
97
|
+
promise: Promise
|
|
98
|
+
) {
|
|
99
|
+
if (pendingPromise != null || pendingSuccessCallback != null) {
|
|
100
|
+
promise.reject("ERR_ALREADY_IN_PROGRESS", "A DocV session is already in progress")
|
|
101
|
+
return
|
|
102
|
+
}
|
|
103
|
+
Log.d(TAG, "launchSocureDocVWithPromise - launch Socure SDK")
|
|
104
|
+
pendingPromise = promise
|
|
105
|
+
startSdk(docVTransactionToken, publicKey, useSocureGov) {
|
|
106
|
+
promise.reject("ERR_NO_ACTIVITY", "App activity is null")
|
|
107
|
+
pendingPromise = null
|
|
84
108
|
}
|
|
85
109
|
}
|
|
86
110
|
|
|
87
|
-
|
|
88
|
-
this.onSuccessCallback = onSuccess
|
|
89
|
-
this.onErrorCallback = onError
|
|
111
|
+
// ── Shared launch logic ──────────────────────────────────────────────────
|
|
90
112
|
|
|
91
|
-
|
|
113
|
+
private fun startSdk(
|
|
114
|
+
docVTransactionToken: String,
|
|
115
|
+
publicKey: String,
|
|
116
|
+
useSocureGov: Boolean,
|
|
117
|
+
onNoActivity: () -> Unit
|
|
118
|
+
) {
|
|
92
119
|
reactApplicationContext.addActivityEventListener(this)
|
|
93
120
|
SocureSdk.setSource(REACT_NATIVE)
|
|
121
|
+
|
|
122
|
+
val activity = reactApplicationContext.currentActivity
|
|
123
|
+
if (activity == null) {
|
|
124
|
+
Log.e(TAG, "Aborting since app activity object is null")
|
|
125
|
+
reactApplicationContext.removeActivityEventListener(this)
|
|
126
|
+
onNoActivity()
|
|
127
|
+
return
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
activity.startActivityForResult(
|
|
131
|
+
SocureSdk.getIntent(
|
|
132
|
+
activity,
|
|
133
|
+
SocureDocVContext(docVTransactionToken, publicKey, useSocureGov, null, null)
|
|
134
|
+
),
|
|
135
|
+
SOCURE_SDK_REQUEST_CODE
|
|
136
|
+
)
|
|
94
137
|
}
|
|
95
138
|
|
|
96
139
|
override fun onActivityResult(
|
|
@@ -99,54 +142,81 @@ class SocureDocVReactNativeModule(reactContext: ReactApplicationContext) :
|
|
|
99
142
|
resultCode: Int,
|
|
100
143
|
data: Intent?
|
|
101
144
|
) {
|
|
102
|
-
if (requestCode
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
145
|
+
if (requestCode != SOCURE_SDK_REQUEST_CODE) {
|
|
146
|
+
Log.d(TAG, "onActivityResult - requestCode does not match: $requestCode")
|
|
147
|
+
return
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
data?.let {
|
|
151
|
+
getResult(it) { result ->
|
|
152
|
+
Log.d(TAG, "onResult called: $result")
|
|
153
|
+
if (result is SocureDocVSuccess) {
|
|
154
|
+
val map = Arguments.createMap().apply {
|
|
155
|
+
putString("deviceSessionToken", result.deviceSessionToken)
|
|
110
156
|
}
|
|
157
|
+
pendingPromise?.resolve(map)
|
|
158
|
+
pendingSuccessCallback?.invoke(map)
|
|
159
|
+
} else {
|
|
160
|
+
val failure = result as SocureDocVFailure
|
|
161
|
+
val code = getErrorCode(failure.error)
|
|
162
|
+
val message = getErrorMessage(failure.error)
|
|
163
|
+
pendingPromise?.reject(code, message)
|
|
164
|
+
pendingErrorCallback?.invoke(buildErrorMap(code, message, failure.deviceSessionToken))
|
|
111
165
|
}
|
|
166
|
+
clearPending()
|
|
112
167
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
TAG,
|
|
118
|
-
"onActivityResult - requestCode does not match: $requestCode, not removing activity event listener"
|
|
119
|
-
)
|
|
168
|
+
} ?: run {
|
|
169
|
+
pendingPromise?.reject("ERR_NO_DATA", "No result data returned from SDK")
|
|
170
|
+
pendingErrorCallback?.invoke(buildErrorMap("ERR_NO_DATA", "No result data returned from SDK", null))
|
|
171
|
+
clearPending()
|
|
120
172
|
}
|
|
173
|
+
|
|
174
|
+
Log.d(TAG, "onActivityResult - removing activity event listener")
|
|
175
|
+
reactApplicationContext.removeActivityEventListener(this)
|
|
121
176
|
}
|
|
122
177
|
|
|
123
178
|
override fun onNewIntent(intent: Intent) {}
|
|
124
179
|
|
|
125
|
-
private fun
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
} else {
|
|
130
|
-
docVResponse.putString("deviceSessionToken", result.deviceSessionToken)
|
|
131
|
-
docVResponse.putString("error", getErrorMessage((result as SocureDocVFailure).error))
|
|
132
|
-
}
|
|
133
|
-
return docVResponse
|
|
180
|
+
private fun clearPending() {
|
|
181
|
+
pendingPromise = null
|
|
182
|
+
pendingSuccessCallback = null
|
|
183
|
+
pendingErrorCallback = null
|
|
134
184
|
}
|
|
135
185
|
|
|
136
|
-
private fun
|
|
137
|
-
|
|
186
|
+
private fun buildErrorMap(code: String, message: String, deviceSessionToken: String?): ReadableMap =
|
|
187
|
+
Arguments.createMap().apply {
|
|
188
|
+
putString("code", code)
|
|
189
|
+
putString("error", message)
|
|
190
|
+
deviceSessionToken?.let { putString("deviceSessionToken", it) }
|
|
191
|
+
}
|
|
138
192
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
SocureDocVError.
|
|
142
|
-
SocureDocVError.
|
|
143
|
-
SocureDocVError.
|
|
144
|
-
SocureDocVError.
|
|
145
|
-
SocureDocVError.
|
|
146
|
-
SocureDocVError.
|
|
147
|
-
SocureDocVError.
|
|
148
|
-
|
|
193
|
+
private fun getErrorCode(socureDocVError: SocureDocVError): String {
|
|
194
|
+
return when (socureDocVError) {
|
|
195
|
+
SocureDocVError.NO_INTERNET_CONNECTION -> "ERR_NO_INTERNET"
|
|
196
|
+
SocureDocVError.SESSION_INITIATION_FAILURE -> "ERR_SESSION_INITIATION"
|
|
197
|
+
SocureDocVError.CAMERA_PERMISSION_DECLINED -> "ERR_CAMERA_PERMISSION"
|
|
198
|
+
SocureDocVError.CONSENT_DECLINED -> "ERR_CONSENT_DECLINED"
|
|
199
|
+
SocureDocVError.DOCUMENT_UPLOAD_FAILURE -> "ERR_UPLOAD_FAILURE"
|
|
200
|
+
SocureDocVError.INVALID_DOCV_TRANSACTION_TOKEN -> "ERR_INVALID_TOKEN"
|
|
201
|
+
SocureDocVError.INVALID_PUBLIC_KEY -> "ERR_INVALID_KEY"
|
|
202
|
+
SocureDocVError.SESSION_EXPIRED -> "ERR_SESSION_EXPIRED"
|
|
203
|
+
SocureDocVError.USER_CANCELED -> "ERR_USER_CANCELED"
|
|
204
|
+
else -> "ERR_UNKNOWN"
|
|
205
|
+
}
|
|
206
|
+
}
|
|
149
207
|
|
|
208
|
+
private fun getErrorMessage(socureDocVError: SocureDocVError): String {
|
|
209
|
+
return when (socureDocVError) {
|
|
210
|
+
SocureDocVError.NO_INTERNET_CONNECTION -> "No internet connection"
|
|
211
|
+
SocureDocVError.SESSION_INITIATION_FAILURE -> "Failed to initiate the session"
|
|
212
|
+
SocureDocVError.CAMERA_PERMISSION_DECLINED -> "Permissions to open the camera declined by the user"
|
|
213
|
+
SocureDocVError.CONSENT_DECLINED -> "Consent declined by the user"
|
|
214
|
+
SocureDocVError.DOCUMENT_UPLOAD_FAILURE -> "Failed to upload the documents"
|
|
215
|
+
SocureDocVError.INVALID_DOCV_TRANSACTION_TOKEN -> "Invalid transaction token"
|
|
216
|
+
SocureDocVError.INVALID_PUBLIC_KEY -> "Invalid or missing SDK key"
|
|
217
|
+
SocureDocVError.SESSION_EXPIRED -> "Session expired"
|
|
218
|
+
SocureDocVError.USER_CANCELED -> "Scan canceled by the user"
|
|
219
|
+
else -> "Unknown error"
|
|
150
220
|
}
|
|
151
221
|
}
|
|
152
|
-
}
|
|
222
|
+
}
|
|
@@ -1,17 +1,31 @@
|
|
|
1
1
|
package com.socure.docv.reactnative
|
|
2
2
|
|
|
3
|
-
import com.facebook.react.
|
|
3
|
+
import com.facebook.react.BaseReactPackage
|
|
4
4
|
import com.facebook.react.bridge.NativeModule
|
|
5
5
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.facebook.react.module.model.ReactModuleInfo
|
|
7
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider
|
|
6
8
|
import com.facebook.react.uimanager.ViewManager
|
|
7
9
|
|
|
10
|
+
class SocureDocVReactNativePackage : BaseReactPackage() {
|
|
11
|
+
override fun getModule(name: String, context: ReactApplicationContext): NativeModule? =
|
|
12
|
+
if (name == SocureDocVReactNativeModule.NAME)
|
|
13
|
+
SocureDocVReactNativeModule(context)
|
|
14
|
+
else null
|
|
8
15
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
16
|
+
override fun getReactModuleInfoProvider() = ReactModuleInfoProvider {
|
|
17
|
+
mapOf(
|
|
18
|
+
SocureDocVReactNativeModule.NAME to ReactModuleInfo(
|
|
19
|
+
SocureDocVReactNativeModule.NAME,
|
|
20
|
+
SocureDocVReactNativeModule.NAME,
|
|
21
|
+
false,
|
|
22
|
+
false,
|
|
23
|
+
false,
|
|
24
|
+
BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
|
|
25
|
+
)
|
|
26
|
+
)
|
|
12
27
|
}
|
|
13
28
|
|
|
14
|
-
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>>
|
|
15
|
-
|
|
16
|
-
}
|
|
29
|
+
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> =
|
|
30
|
+
emptyList()
|
|
17
31
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
package com.socure.docv.reactnative
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.Callback
|
|
4
|
+
import com.facebook.react.bridge.Promise
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
7
|
+
|
|
8
|
+
abstract class NativeSocureDocVReactNativeSpec(context: ReactApplicationContext) :
|
|
9
|
+
ReactContextBaseJavaModule(context) {
|
|
10
|
+
|
|
11
|
+
abstract fun launchSocureDocVWithPromise(
|
|
12
|
+
docVTransactionToken: String,
|
|
13
|
+
publicKey: String,
|
|
14
|
+
useSocureGov: Boolean,
|
|
15
|
+
promise: Promise,
|
|
16
|
+
)
|
|
17
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
#import <React/RCTBridgeModule.h>
|
|
2
|
+
#import "socure_docv_react_native-Swift.h"
|
|
3
|
+
|
|
4
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
5
|
+
#import <ReactCommon/RCTTurboModule.h>
|
|
6
|
+
#import <SocureDocVReactNative/SocureDocVReactNative.h>
|
|
7
|
+
|
|
8
|
+
@interface SocureDocVReactNative : NSObject <NativeSocureDocVReactNativeSpec>
|
|
9
|
+
@end
|
|
10
|
+
|
|
11
|
+
@implementation SocureDocVReactNative
|
|
12
|
+
|
|
13
|
+
RCT_EXPORT_MODULE()
|
|
14
|
+
|
|
15
|
+
// Promise-based API (new)
|
|
16
|
+
- (void)launchSocureDocVWithPromise:(NSString *)docVTransactionToken
|
|
17
|
+
publicKey:(NSString *)publicKey
|
|
18
|
+
useSocureGov:(BOOL)useSocureGov
|
|
19
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
20
|
+
reject:(RCTPromiseRejectBlock)reject {
|
|
21
|
+
[SocureDocVHelper launchWithPromiseToken:docVTransactionToken
|
|
22
|
+
apiKey:publicKey
|
|
23
|
+
useSocureGov:useSocureGov
|
|
24
|
+
resolve:resolve
|
|
25
|
+
reject:reject];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Callback-based API (legacy)
|
|
29
|
+
RCT_EXPORT_METHOD(launchSocureDocV:(NSString *)docVTransactionToken
|
|
30
|
+
publicKey:(NSString *)publicKey
|
|
31
|
+
useSocureGov:(BOOL)useSocureGov
|
|
32
|
+
onSuccess:(RCTResponseSenderBlock)onSuccess
|
|
33
|
+
onError:(RCTResponseSenderBlock)onError) {
|
|
34
|
+
[SocureDocVHelper launchWithToken:docVTransactionToken
|
|
35
|
+
apiKey:publicKey
|
|
36
|
+
useSocureGov:useSocureGov
|
|
37
|
+
onSuccess:onSuccess
|
|
38
|
+
onError:onError];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
|
|
42
|
+
(const facebook::react::ObjCTurboModule::InitParams &)params {
|
|
43
|
+
return std::make_shared<facebook::react::NativeSocureDocVReactNativeSpecJSI>(params);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@end
|
|
47
|
+
|
|
48
|
+
#else // Old Architecture
|
|
49
|
+
|
|
50
|
+
@interface RCT_EXTERN_MODULE(SocureDocVReactNative, NSObject)
|
|
51
|
+
|
|
52
|
+
// Promise-based API (new)
|
|
53
|
+
RCT_EXTERN_METHOD(launchSocureDocVWithPromise:(NSString)docVTransactionToken
|
|
54
|
+
publicKey:(NSString)publicKey
|
|
55
|
+
useSocureGov:(BOOL)useSocureGov
|
|
56
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
57
|
+
reject:(RCTPromiseRejectBlock)reject)
|
|
58
|
+
|
|
59
|
+
// Callback-based API (legacy)
|
|
60
|
+
RCT_EXTERN_METHOD(launchSocureDocV:(NSString)docVTransactionToken
|
|
61
|
+
publicKey:(NSString)publicKey
|
|
62
|
+
useSocureGov:(BOOL)useSocureGov
|
|
63
|
+
onSuccess:(RCTResponseSenderBlock)onSuccess
|
|
64
|
+
onError:(RCTResponseSenderBlock)onError)
|
|
65
|
+
|
|
66
|
+
@end
|
|
67
|
+
|
|
68
|
+
#endif
|
|
@@ -1,75 +1,109 @@
|
|
|
1
1
|
import SocureDocV
|
|
2
2
|
|
|
3
|
-
@objc(
|
|
4
|
-
class
|
|
3
|
+
@objc(SocureDocVHelper)
|
|
4
|
+
class SocureDocVHelper: NSObject {
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
// Promise-based API (new)
|
|
7
|
+
@objc static func launch(
|
|
8
|
+
withPromiseToken docVTransactionToken: String,
|
|
9
|
+
apiKey socureApiKey: String,
|
|
10
|
+
useSocureGov: Bool,
|
|
11
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
12
|
+
reject: @escaping RCTPromiseRejectBlock
|
|
13
|
+
) {
|
|
14
|
+
DispatchQueue.main.async {
|
|
15
|
+
guard let root = RCTPresentedViewController() else {
|
|
16
|
+
reject("ERR_NO_VIEW_CONTROLLER", "Failed to get root view controller", nil)
|
|
17
|
+
return
|
|
18
|
+
}
|
|
12
19
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
let options = SocureDocVOptions(
|
|
20
|
-
publicKey: socureApiKey,
|
|
21
|
-
docvTransactionToken: docVTransactionToken,
|
|
22
|
-
presentingViewController: root,
|
|
23
|
-
useSocureGov: useSocureGov
|
|
24
|
-
)
|
|
20
|
+
let options = SocureDocVOptions(
|
|
21
|
+
publicKey: socureApiKey,
|
|
22
|
+
docvTransactionToken: docVTransactionToken,
|
|
23
|
+
presentingViewController: root,
|
|
24
|
+
useSocureGov: useSocureGov
|
|
25
|
+
)
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
}
|
|
27
|
+
SocureDocVSDK.launch(options) { result in
|
|
28
|
+
DispatchQueue.main.async {
|
|
29
|
+
switch result {
|
|
30
|
+
case .success(let success):
|
|
31
|
+
resolve(["deviceSessionToken": success.deviceSessionToken])
|
|
32
|
+
case .failure(let failure):
|
|
33
|
+
let code = SocureDocVHelper.errorCode(from: failure.error)
|
|
34
|
+
let message = SocureDocVHelper.errorMessage(from: failure.error)
|
|
35
|
+
reject(code, message, nil)
|
|
36
|
+
}
|
|
38
37
|
}
|
|
38
|
+
}
|
|
39
39
|
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Callback-based API (legacy)
|
|
43
|
+
@objc static func launch(
|
|
44
|
+
withToken docVTransactionToken: String,
|
|
45
|
+
apiKey socureApiKey: String,
|
|
46
|
+
useSocureGov: Bool,
|
|
47
|
+
onSuccess: @escaping RCTResponseSenderBlock,
|
|
48
|
+
onError: @escaping RCTResponseSenderBlock
|
|
49
|
+
) {
|
|
50
|
+
DispatchQueue.main.async {
|
|
51
|
+
guard let root = RCTPresentedViewController() else {
|
|
52
|
+
onError([["code": "ERR_NO_VIEW_CONTROLLER", "error": "Failed to get root view controller"]])
|
|
53
|
+
return
|
|
54
|
+
}
|
|
40
55
|
|
|
41
|
-
|
|
42
|
-
|
|
56
|
+
let options = SocureDocVOptions(
|
|
57
|
+
publicKey: socureApiKey,
|
|
58
|
+
docvTransactionToken: docVTransactionToken,
|
|
59
|
+
presentingViewController: root,
|
|
60
|
+
useSocureGov: useSocureGov
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
SocureDocVSDK.launch(options) { result in
|
|
64
|
+
DispatchQueue.main.async {
|
|
65
|
+
switch result {
|
|
66
|
+
case .success(let success):
|
|
67
|
+
onSuccess([["deviceSessionToken": success.deviceSessionToken]])
|
|
68
|
+
case .failure(let failure):
|
|
69
|
+
let code = SocureDocVHelper.errorCode(from: failure.error)
|
|
70
|
+
let message = SocureDocVHelper.errorMessage(from: failure.error)
|
|
71
|
+
onError([["code": code, "error": message, "deviceSessionToken": failure.deviceSessionToken]])
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
43
75
|
}
|
|
76
|
+
}
|
|
44
77
|
|
|
45
|
-
|
|
46
|
-
|
|
78
|
+
private static func errorCode(from error: SocureDocVError) -> String {
|
|
79
|
+
switch error {
|
|
80
|
+
case .noInternetConnection: return "ERR_NO_INTERNET"
|
|
81
|
+
case .sessionInitiationFailure: return "ERR_SESSION_INITIATION"
|
|
82
|
+
case .cameraPermissionDeclined: return "ERR_CAMERA_PERMISSION"
|
|
83
|
+
case .consentDeclined: return "ERR_CONSENT_DECLINED"
|
|
84
|
+
case .documentUploadFailure: return "ERR_UPLOAD_FAILURE"
|
|
85
|
+
case .invalidDocvTransactionToken: return "ERR_INVALID_TOKEN"
|
|
86
|
+
case .invalidPublicKey: return "ERR_INVALID_KEY"
|
|
87
|
+
case .sessionExpired: return "ERR_SESSION_EXPIRED"
|
|
88
|
+
case .userCanceled: return "ERR_USER_CANCELED"
|
|
89
|
+
case .unknown: fallthrough
|
|
90
|
+
@unknown default: return "ERR_UNKNOWN"
|
|
47
91
|
}
|
|
92
|
+
}
|
|
48
93
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return "Invalid transaction token"
|
|
63
|
-
case .invalidPublicKey:
|
|
64
|
-
return "Invalid or missing SDK key"
|
|
65
|
-
case .sessionExpired:
|
|
66
|
-
return "Session expired"
|
|
67
|
-
case .userCanceled:
|
|
68
|
-
return "Scan canceled by the user"
|
|
69
|
-
case .unknown:
|
|
70
|
-
fallthrough
|
|
71
|
-
@unknown default:
|
|
72
|
-
return "Unknown error"
|
|
73
|
-
}
|
|
94
|
+
private static func errorMessage(from error: SocureDocVError) -> String {
|
|
95
|
+
switch error {
|
|
96
|
+
case .noInternetConnection: return "No internet connection"
|
|
97
|
+
case .sessionInitiationFailure: return "Failed to initiate the session"
|
|
98
|
+
case .cameraPermissionDeclined: return "Permissions to open the camera declined by the user"
|
|
99
|
+
case .consentDeclined: return "Consent declined by the user"
|
|
100
|
+
case .documentUploadFailure: return "Failed to upload the documents"
|
|
101
|
+
case .invalidDocvTransactionToken: return "Invalid transaction token"
|
|
102
|
+
case .invalidPublicKey: return "Invalid or missing SDK key"
|
|
103
|
+
case .sessionExpired: return "Session expired"
|
|
104
|
+
case .userCanceled: return "Scan canceled by the user"
|
|
105
|
+
case .unknown: fallthrough
|
|
106
|
+
@unknown default: return "Unknown error"
|
|
74
107
|
}
|
|
108
|
+
}
|
|
75
109
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _reactNative = require("react-native");
|
|
8
|
+
var _default = exports.default = _reactNative.TurboModuleRegistry.getEnforcing('SocureDocVReactNative');
|
|
9
|
+
//# sourceMappingURL=NativeSocureDocVReactNative.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_default","exports","default","TurboModuleRegistry","getEnforcing"],"sources":["NativeSocureDocVReactNative.ts"],"sourcesContent":["import type { TurboModule } from 'react-native';\nimport { TurboModuleRegistry } from 'react-native';\n\nexport type DocVResult = {\n deviceSessionToken: string;\n};\n\nexport interface Spec extends TurboModule {\n launchSocureDocVWithPromise(\n docVTransactionToken: string,\n publicKey: string,\n useSocureGov: boolean\n ): Promise<DocVResult>;\n}\n\nexport default TurboModuleRegistry.getEnforcing<Spec>('SocureDocVReactNative');\n"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAAmD,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAcpCC,gCAAmB,CAACC,YAAY,CAAO,uBAAuB,CAAC","ignoreList":[]}
|
package/lib/commonjs/index.js
CHANGED
|
@@ -4,7 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.launchSocureDocV = launchSocureDocV;
|
|
7
|
+
exports.launchSocureDocVWithPromise = launchSocureDocVWithPromise;
|
|
7
8
|
var _reactNative = require("react-native");
|
|
9
|
+
var _NativeSocureDocVReactNative = _interopRequireDefault(require("./NativeSocureDocVReactNative"));
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
// ── Callback-based API (legacy, preserved for easy migration) ────────────────
|
|
12
|
+
|
|
8
13
|
const LINKING_ERROR = `The package '@socure-inc/docv-react-native' doesn't seem to be linked.\n\n` + '- Rebuilt the app after installing the package';
|
|
9
14
|
const SocureDocVReactNative = _reactNative.NativeModules.SocureDocVReactNative ? _reactNative.NativeModules.SocureDocVReactNative : new Proxy({}, {
|
|
10
15
|
get() {
|
|
@@ -12,6 +17,20 @@ const SocureDocVReactNative = _reactNative.NativeModules.SocureDocVReactNative ?
|
|
|
12
17
|
}
|
|
13
18
|
});
|
|
14
19
|
function launchSocureDocV(docVTransactionToken, publicKey, useSocureGov, onSuccess, onError) {
|
|
15
|
-
|
|
20
|
+
// Under New Architecture, NativeModules may not expose the callback method.
|
|
21
|
+
// Fall back to the TurboModule promise API so callbacks still work.
|
|
22
|
+
if (typeof SocureDocVReactNative.launchSocureDocV === 'function') {
|
|
23
|
+
return SocureDocVReactNative.launchSocureDocV(docVTransactionToken, publicKey, useSocureGov, onSuccess, onError);
|
|
24
|
+
}
|
|
25
|
+
_NativeSocureDocVReactNative.default.launchSocureDocVWithPromise(docVTransactionToken, publicKey, useSocureGov).then(result => onSuccess(result)).catch(err => onError({
|
|
26
|
+
code: err.code,
|
|
27
|
+
error: err.message
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// ── Promise-based API (new) ──────────────────────────────────────────────────
|
|
32
|
+
|
|
33
|
+
function launchSocureDocVWithPromise(docVTransactionToken, publicKey, useSocureGov) {
|
|
34
|
+
return _NativeSocureDocVReactNative.default.launchSocureDocVWithPromise(docVTransactionToken, publicKey, useSocureGov);
|
|
16
35
|
}
|
|
17
36
|
//# sourceMappingURL=index.js.map
|