@smile_identity/react-native 10.1.1 → 10.1.3-rc.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/android/gradle.properties +1 -1
- package/android/src/main/java/com/smileidentity/react/SmileIdModule.kt +120 -5
- package/android/src/main/java/com/smileidentity/react/SmileIdPackage.kt +2 -2
- package/android/src/oldarch/SmileIdSpec.kt +14 -0
- package/ios/RNSmileID.mm +7 -0
- package/ios/RNSmileID.swift +145 -87
- package/ios/Utils/SmileIDDictExt.swift +35 -3
- package/ios/View/SmileIDBiometricKYCView.swift +9 -9
- package/ios/View/SmileIDDocumentVerificationView.swift +6 -7
- package/ios/View/SmileIDEnhancedDocumentVerificationView.swift +8 -9
- package/ios/View/SmileIDSmartSelfieAuthView.swift +6 -7
- package/ios/View/SmileIDSmartSelfieEnrollmentView.swift +6 -7
- package/lib/commonjs/NativeSmileId.js.map +1 -1
- package/lib/commonjs/SmileIDBiometricKYCView.js.map +1 -1
- package/lib/commonjs/SmileIDConsentView.js.map +1 -1
- package/lib/commonjs/SmileIDDocumentVerificationView.js.map +1 -1
- package/lib/commonjs/SmileIDEnhancedDocumentVerificationView.js.map +1 -1
- package/lib/commonjs/SmileIDSmartSelfieAuthenticationView.js.map +1 -1
- package/lib/commonjs/SmileIDSmartSelfieEnrollmentView.js.map +1 -1
- package/lib/commonjs/index.js +27 -72
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/NativeSmileId.js.map +1 -1
- package/lib/module/SmileIDBiometricKYCView.js.map +1 -1
- package/lib/module/SmileIDConsentView.js.map +1 -1
- package/lib/module/SmileIDDocumentVerificationView.js.map +1 -1
- package/lib/module/SmileIDEnhancedDocumentVerificationView.js.map +1 -1
- package/lib/module/SmileIDSmartSelfieAuthenticationView.js.map +1 -1
- package/lib/module/SmileIDSmartSelfieEnrollmentView.js.map +1 -1
- package/lib/module/index.js +27 -8
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/NativeSmileId.d.ts +33 -0
- package/lib/typescript/NativeSmileId.d.ts.map +1 -1
- package/lib/typescript/SmileIDBiometricKYCView.d.ts +1 -1
- package/lib/typescript/SmileIDBiometricKYCView.d.ts.map +1 -1
- package/lib/typescript/SmileIDConsentView.d.ts +1 -1
- package/lib/typescript/SmileIDConsentView.d.ts.map +1 -1
- package/lib/typescript/SmileIDDocumentVerificationView.d.ts +1 -1
- package/lib/typescript/SmileIDDocumentVerificationView.d.ts.map +1 -1
- package/lib/typescript/SmileIDEnhancedDocumentVerificationView.d.ts +1 -1
- package/lib/typescript/SmileIDEnhancedDocumentVerificationView.d.ts.map +1 -1
- package/lib/typescript/SmileIDSmartSelfieAuthenticationView.d.ts +1 -1
- package/lib/typescript/SmileIDSmartSelfieAuthenticationView.d.ts.map +1 -1
- package/lib/typescript/SmileIDSmartSelfieEnrollmentView.d.ts +1 -1
- package/lib/typescript/SmileIDSmartSelfieEnrollmentView.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +42 -20
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/types.d.ts +1 -1
- package/lib/typescript/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/react-native-smile-id.podspec +1 -1
- package/src/NativeSmileId.ts +40 -0
- package/src/SmileIDBiometricKYCView.tsx +3 -7
- package/src/SmileIDConsentView.tsx +3 -7
- package/src/SmileIDDocumentVerificationView.tsx +3 -7
- package/src/SmileIDEnhancedDocumentVerificationView.tsx +3 -7
- package/src/SmileIDSmartSelfieAuthenticationView.tsx +3 -7
- package/src/SmileIDSmartSelfieEnrollmentView.tsx +3 -7
- package/src/index.tsx +45 -12
- package/src/types.ts +1 -1
|
@@ -1,23 +1,40 @@
|
|
|
1
1
|
package com.smileidentity.react
|
|
2
2
|
|
|
3
|
+
import android.util.Log
|
|
4
|
+
import com.facebook.react.bridge.Arguments
|
|
3
5
|
import com.facebook.react.bridge.Promise
|
|
4
6
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
5
7
|
import com.facebook.react.bridge.ReactMethod
|
|
6
8
|
import com.facebook.react.bridge.ReadableMap
|
|
9
|
+
import com.facebook.react.bridge.WritableArray
|
|
7
10
|
import com.smileidentity.SmileID
|
|
8
11
|
import com.smileidentity.SmileIDCrashReporting
|
|
9
12
|
import com.smileidentity.SmileIdSpec
|
|
13
|
+
import com.smileidentity.models.AuthenticationResponse
|
|
14
|
+
import com.smileidentity.models.BiometricKycJobStatusResponse
|
|
15
|
+
import com.smileidentity.models.DocumentVerificationJobStatusResponse
|
|
16
|
+
import com.smileidentity.models.EnhancedDocumentVerificationJobStatusResponse
|
|
17
|
+
import com.smileidentity.models.EnhancedKycAsyncResponse
|
|
10
18
|
import com.smileidentity.models.EnhancedKycRequest
|
|
19
|
+
import com.smileidentity.models.EnhancedKycResponse
|
|
20
|
+
import com.smileidentity.models.PrepUploadResponse
|
|
21
|
+
import com.smileidentity.models.ProductsConfigResponse
|
|
22
|
+
import com.smileidentity.models.ServicesResponse
|
|
23
|
+
import com.smileidentity.models.SmartSelfieJobStatusResponse
|
|
24
|
+
import com.smileidentity.models.ValidDocumentsResponse
|
|
11
25
|
import com.smileidentity.networking.pollBiometricKycJobStatus
|
|
12
26
|
import com.smileidentity.networking.pollDocumentVerificationJobStatus
|
|
13
27
|
import com.smileidentity.networking.pollEnhancedDocumentVerificationJobStatus
|
|
14
28
|
import com.smileidentity.networking.pollSmartSelfieJobStatus
|
|
15
29
|
import com.smileidentity.react.utils.getIntOrDefault
|
|
16
30
|
import com.smileidentity.react.utils.getStringOrDefault
|
|
31
|
+
import com.smileidentity.results.SmartSelfieResult
|
|
32
|
+
import java.net.URL
|
|
17
33
|
import kotlinx.coroutines.CoroutineExceptionHandler
|
|
18
34
|
import kotlinx.coroutines.CoroutineScope
|
|
19
35
|
import kotlinx.coroutines.Dispatchers
|
|
20
36
|
import kotlinx.coroutines.flow.Flow
|
|
37
|
+
import kotlinx.coroutines.flow.last
|
|
21
38
|
import kotlinx.coroutines.flow.map
|
|
22
39
|
import kotlinx.coroutines.flow.single
|
|
23
40
|
import kotlinx.coroutines.launch
|
|
@@ -39,56 +56,127 @@ class SmileIdModule internal constructor(context: ReactApplicationContext) :
|
|
|
39
56
|
promise.resolve(null)
|
|
40
57
|
}
|
|
41
58
|
|
|
59
|
+
@ReactMethod
|
|
60
|
+
override fun setEnvironment(useSandBox: Boolean, promise: Promise) {
|
|
61
|
+
SmileID.setEnvironment(useSandbox = useSandBox)
|
|
62
|
+
promise.resolve(null)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@ReactMethod
|
|
66
|
+
override fun setCallbackUrl(callbackUrl: String, promise: Promise) {
|
|
67
|
+
SmileID.setCallbackUrl(callbackUrl = URL(callbackUrl))
|
|
68
|
+
promise.resolve(null)
|
|
69
|
+
}
|
|
70
|
+
|
|
42
71
|
@ReactMethod
|
|
43
72
|
override fun disableCrashReporting(promise: Promise) {
|
|
44
73
|
SmileIDCrashReporting.disable()
|
|
45
74
|
}
|
|
46
75
|
|
|
76
|
+
@ReactMethod
|
|
77
|
+
override fun setAllowOfflineMode(allowOfflineMode: Boolean, promise: Promise) {
|
|
78
|
+
SmileID.setAllowOfflineMode(allowOfflineMode)
|
|
79
|
+
promise.resolve(null)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
@ReactMethod
|
|
83
|
+
override fun submitJob(jobId: String, promise: Promise) = launch(
|
|
84
|
+
work = { SmileID.submitJob(jobId) },
|
|
85
|
+
clazz = Unit::class.java,
|
|
86
|
+
promise = promise
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
@ReactMethod
|
|
90
|
+
override fun getUnsubmittedJobs(promise: Promise) {
|
|
91
|
+
try {
|
|
92
|
+
val writableArray: WritableArray = Arguments.createArray()
|
|
93
|
+
SmileID.getUnsubmittedJobs().forEach {
|
|
94
|
+
writableArray.pushString(it)
|
|
95
|
+
}
|
|
96
|
+
promise.resolve(writableArray)
|
|
97
|
+
} catch (e: Exception) {
|
|
98
|
+
promise.reject(e)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
@ReactMethod
|
|
103
|
+
override fun getSubmittedJobs(promise: Promise) {
|
|
104
|
+
try {
|
|
105
|
+
val writableArray: WritableArray = Arguments.createArray()
|
|
106
|
+
SmileID.getSubmittedJobs().forEach {
|
|
107
|
+
writableArray.pushString(it)
|
|
108
|
+
}
|
|
109
|
+
promise.resolve(writableArray)
|
|
110
|
+
} catch (e: Exception) {
|
|
111
|
+
promise.reject(e)
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
@ReactMethod
|
|
116
|
+
override fun cleanup(jobId: String, promise: Promise) {
|
|
117
|
+
try {
|
|
118
|
+
SmileID.cleanup(jobId)
|
|
119
|
+
promise.resolve(null)
|
|
120
|
+
} catch (e: Exception) {
|
|
121
|
+
promise.resolve(e)
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
47
125
|
@ReactMethod
|
|
48
126
|
override fun authenticate(request: ReadableMap, promise: Promise) = launch(
|
|
49
|
-
work = {
|
|
127
|
+
work = {
|
|
128
|
+
SmileID.api.authenticate(request = request.toAuthenticationRequest())
|
|
129
|
+
},
|
|
130
|
+
clazz = AuthenticationResponse::class.java,
|
|
50
131
|
promise = promise
|
|
51
132
|
)
|
|
52
133
|
|
|
53
134
|
@ReactMethod
|
|
54
135
|
override fun prepUpload(request: ReadableMap, promise: Promise) = launch(
|
|
55
136
|
work = { SmileID.api.prepUpload(request = request.toPrepUploadRequest()) },
|
|
137
|
+
clazz = PrepUploadResponse::class.java,
|
|
56
138
|
promise = promise
|
|
57
139
|
)
|
|
58
140
|
|
|
59
141
|
@ReactMethod
|
|
60
142
|
override fun upload(url: String, request: ReadableMap, promise: Promise) = launch(
|
|
61
143
|
work = { SmileID.api.upload(url, request.toUploadRequest()) },
|
|
144
|
+
clazz = Unit::class.java,
|
|
62
145
|
promise = promise
|
|
63
146
|
)
|
|
64
147
|
|
|
65
148
|
@ReactMethod
|
|
66
149
|
override fun doEnhancedKyc(request: ReadableMap, promise: Promise) = launch(
|
|
67
150
|
work = { SmileID.api.doEnhancedKyc(request = request.toEnhancedKycRequest()) },
|
|
151
|
+
clazz = EnhancedKycResponse::class.java,
|
|
68
152
|
promise = promise
|
|
69
153
|
)
|
|
70
154
|
|
|
71
155
|
@ReactMethod
|
|
72
156
|
override fun doEnhancedKycAsync(request: ReadableMap, promise: Promise) = launch(
|
|
73
157
|
work = { SmileID.api.doEnhancedKycAsync(request = request.toEnhancedKycRequest()) },
|
|
158
|
+
clazz = EnhancedKycAsyncResponse::class.java,
|
|
74
159
|
promise = promise
|
|
75
160
|
)
|
|
76
161
|
|
|
77
162
|
@ReactMethod
|
|
78
163
|
override fun getSmartSelfieJobStatus(request: ReadableMap, promise: Promise) = launch(
|
|
79
164
|
work = { SmileID.api.getSmartSelfieJobStatus(request = request.toJobStatusRequest()) },
|
|
165
|
+
clazz = SmartSelfieJobStatusResponse::class.java,
|
|
80
166
|
promise = promise
|
|
81
167
|
)
|
|
82
168
|
|
|
83
169
|
@ReactMethod
|
|
84
170
|
override fun getDocumentVerificationJobStatus(request: ReadableMap, promise: Promise) = launch(
|
|
85
171
|
work = { SmileID.api.getDocumentVerificationJobStatus(request = request.toJobStatusRequest()) },
|
|
172
|
+
clazz = DocumentVerificationJobStatusResponse::class.java,
|
|
86
173
|
promise = promise
|
|
87
174
|
)
|
|
88
175
|
|
|
89
176
|
@ReactMethod
|
|
90
177
|
override fun getBiometricKycJobStatus(request: ReadableMap, promise: Promise) = launch(
|
|
91
178
|
work = { SmileID.api.getBiometricKycJobStatus(request = request.toJobStatusRequest()) },
|
|
179
|
+
clazz = BiometricKycJobStatusResponse::class.java,
|
|
92
180
|
promise = promise
|
|
93
181
|
)
|
|
94
182
|
|
|
@@ -96,24 +184,28 @@ class SmileIdModule internal constructor(context: ReactApplicationContext) :
|
|
|
96
184
|
override fun getEnhancedDocumentVerificationJobStatus(request: ReadableMap, promise: Promise) =
|
|
97
185
|
launch(
|
|
98
186
|
work = { SmileID.api.getEnhancedDocumentVerificationJobStatus(request = request.toJobStatusRequest()) },
|
|
187
|
+
clazz = EnhancedDocumentVerificationJobStatusResponse::class.java,
|
|
99
188
|
promise = promise
|
|
100
189
|
)
|
|
101
190
|
|
|
102
191
|
@ReactMethod
|
|
103
192
|
override fun getProductsConfig(request: ReadableMap, promise: Promise) = launch(
|
|
104
193
|
work = { SmileID.api.getProductsConfig(request = request.toProductsConfigRequest()) },
|
|
194
|
+
clazz = ProductsConfigResponse::class.java,
|
|
105
195
|
promise = promise
|
|
106
196
|
)
|
|
107
197
|
|
|
108
198
|
@ReactMethod
|
|
109
199
|
override fun getValidDocuments(request: ReadableMap, promise: Promise) = launch(
|
|
110
200
|
work = { SmileID.api.getValidDocuments(request = request.toProductsConfigRequest()) },
|
|
201
|
+
clazz = ValidDocumentsResponse::class.java,
|
|
111
202
|
promise = promise
|
|
112
203
|
)
|
|
113
204
|
|
|
114
205
|
@ReactMethod
|
|
115
206
|
override fun getServices(promise: Promise) = launch(
|
|
116
207
|
work = { SmileID.api.getServices() },
|
|
208
|
+
clazz = ServicesResponse::class.java,
|
|
117
209
|
promise = promise
|
|
118
210
|
)
|
|
119
211
|
|
|
@@ -134,6 +226,7 @@ class SmileIdModule internal constructor(context: ReactApplicationContext) :
|
|
|
134
226
|
numAttempts = numAttempts.toLong(),
|
|
135
227
|
)
|
|
136
228
|
},
|
|
229
|
+
clazz = SmartSelfieJobStatusResponse::class.java,
|
|
137
230
|
promise = promise
|
|
138
231
|
)
|
|
139
232
|
|
|
@@ -154,6 +247,7 @@ class SmileIdModule internal constructor(context: ReactApplicationContext) :
|
|
|
154
247
|
numAttempts = numAttempts.toLong(),
|
|
155
248
|
)
|
|
156
249
|
},
|
|
250
|
+
clazz = DocumentVerificationJobStatusResponse::class.java,
|
|
157
251
|
promise = promise
|
|
158
252
|
)
|
|
159
253
|
|
|
@@ -174,6 +268,7 @@ class SmileIdModule internal constructor(context: ReactApplicationContext) :
|
|
|
174
268
|
numAttempts = numAttempts.toLong(),
|
|
175
269
|
)
|
|
176
270
|
},
|
|
271
|
+
clazz = BiometricKycJobStatusResponse::class.java,
|
|
177
272
|
promise = promise
|
|
178
273
|
)
|
|
179
274
|
|
|
@@ -195,6 +290,7 @@ class SmileIdModule internal constructor(context: ReactApplicationContext) :
|
|
|
195
290
|
numAttempts = numAttempts.toLong(),
|
|
196
291
|
)
|
|
197
292
|
},
|
|
293
|
+
clazz = EnhancedDocumentVerificationJobStatusResponse::class.java,
|
|
198
294
|
promise = promise
|
|
199
295
|
)
|
|
200
296
|
|
|
@@ -208,8 +304,10 @@ class SmileIdModule internal constructor(context: ReactApplicationContext) :
|
|
|
208
304
|
val response =
|
|
209
305
|
withContext(Dispatchers.IO) {
|
|
210
306
|
apiCall(request, interval.milliseconds, numAttempts.toInt())
|
|
211
|
-
.map {
|
|
212
|
-
|
|
307
|
+
.map {
|
|
308
|
+
it
|
|
309
|
+
}
|
|
310
|
+
.last()
|
|
213
311
|
}
|
|
214
312
|
response
|
|
215
313
|
} catch (e: Exception) {
|
|
@@ -217,16 +315,33 @@ class SmileIdModule internal constructor(context: ReactApplicationContext) :
|
|
|
217
315
|
}
|
|
218
316
|
}
|
|
219
317
|
|
|
318
|
+
private fun <T> toJson(result: T, clazz: Class<T>): String {
|
|
319
|
+
val adapter = SmileID.moshi.adapter(clazz)
|
|
320
|
+
return adapter.toJson(result)
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
|
|
220
324
|
private fun <T> launch(
|
|
221
325
|
work: suspend () -> T,
|
|
326
|
+
clazz: Class<T>,
|
|
222
327
|
promise: Promise,
|
|
223
328
|
scope: CoroutineScope = CoroutineScope(Dispatchers.IO)
|
|
224
329
|
) {
|
|
225
330
|
val handler = CoroutineExceptionHandler { _, throwable ->
|
|
226
|
-
promise.reject(throwable
|
|
331
|
+
promise.reject(throwable)
|
|
227
332
|
}
|
|
228
333
|
scope.launch(handler) {
|
|
229
|
-
|
|
334
|
+
try {
|
|
335
|
+
val result = work()
|
|
336
|
+
if (clazz == Unit::class.java) {
|
|
337
|
+
promise.resolve(null)
|
|
338
|
+
} else {
|
|
339
|
+
val jsonResult = toJson(result, clazz)
|
|
340
|
+
promise.resolve(jsonResult)
|
|
341
|
+
}
|
|
342
|
+
} catch (e: Exception) {
|
|
343
|
+
promise.reject(e)
|
|
344
|
+
}
|
|
230
345
|
}
|
|
231
346
|
}
|
|
232
347
|
|
|
@@ -36,7 +36,7 @@ class SmileIdPackage : TurboReactPackage() {
|
|
|
36
36
|
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
|
|
37
37
|
return ReactModuleInfoProvider {
|
|
38
38
|
val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap()
|
|
39
|
-
|
|
39
|
+
|
|
40
40
|
moduleInfos[SmileIdModule.NAME] = ReactModuleInfo(
|
|
41
41
|
SmileIdModule.NAME,
|
|
42
42
|
SmileIdModule.NAME,
|
|
@@ -44,7 +44,7 @@ class SmileIdPackage : TurboReactPackage() {
|
|
|
44
44
|
false, // needsEagerInit
|
|
45
45
|
true, // hasConstants
|
|
46
46
|
false, // isCxxModule
|
|
47
|
-
|
|
47
|
+
false // isTurboModule
|
|
48
48
|
)
|
|
49
49
|
moduleInfos
|
|
50
50
|
}
|
|
@@ -10,6 +10,20 @@ abstract class SmileIdSpec internal constructor(context: ReactApplicationContext
|
|
|
10
10
|
|
|
11
11
|
abstract fun initialize(useSandBox: Boolean ,promise: Promise)
|
|
12
12
|
|
|
13
|
+
abstract fun setEnvironment(useSandbox: Boolean, promise: Promise)
|
|
14
|
+
|
|
15
|
+
abstract fun setCallbackUrl(callbackUrl: String, promise: Promise)
|
|
16
|
+
|
|
17
|
+
abstract fun setAllowOfflineMode(allowOfflineMode: Boolean ,promise: Promise)
|
|
18
|
+
|
|
19
|
+
abstract fun submitJob(jobId: String ,promise: Promise)
|
|
20
|
+
|
|
21
|
+
abstract fun getUnsubmittedJobs(promise: Promise)
|
|
22
|
+
|
|
23
|
+
abstract fun getSubmittedJobs(promise: Promise)
|
|
24
|
+
|
|
25
|
+
abstract fun cleanup(jobId: String ,promise: Promise)
|
|
26
|
+
|
|
13
27
|
abstract fun disableCrashReporting(promise: Promise)
|
|
14
28
|
|
|
15
29
|
abstract fun authenticate(request: ReadableMap, promise: Promise)
|
package/ios/RNSmileID.mm
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
@interface RCT_EXTERN_MODULE(RNSmileID, NSObject)
|
|
4
4
|
RCT_EXTERN_METHOD(initialize:(BOOL)useSandBox withResolver:(RCTPromiseResolveBlock)resolve withRejecter:(RCTPromiseRejectBlock)reject)
|
|
5
|
+
RCT_EXTERN_METHOD(setEnvironment:(BOOL)useSandBox withResolver:(RCTPromiseResolveBlock)resolve withRejecter:(RCTPromiseRejectBlock)reject)
|
|
6
|
+
RCT_EXTERN_METHOD(setCallbackUrl:(NSString)callbackUrl withResolver:(RCTPromiseResolveBlock)resolve withRejecter:(RCTPromiseRejectBlock)reject)
|
|
7
|
+
RCT_EXTERN_METHOD(setAllowOfflineMode:(BOOL)allowOfflineMode withResolver:(RCTPromiseResolveBlock)resolve withRejecter:(RCTPromiseRejectBlock)reject)
|
|
8
|
+
RCT_EXTERN_METHOD(submitJob:(NSString *)jobId withResolver:(RCTPromiseResolveBlock)resolve withRejecter:(RCTPromiseRejectBlock)reject)
|
|
9
|
+
RCT_EXTERN_METHOD(getUnsubmittedJobs:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
|
|
10
|
+
RCT_EXTERN_METHOD(getSubmittedJobs:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
|
|
11
|
+
RCT_EXTERN_METHOD(cleanup:(NSString *)jobId withResolver:(RCTPromiseResolveBlock)resolve withRejecter:(RCTPromiseRejectBlock)reject)
|
|
5
12
|
RCT_EXTERN_METHOD(authenticate:(NSDictionary *)request withResolver:(RCTPromiseResolveBlock)resolve withRejecter:(RCTPromiseRejectBlock)reject)
|
|
6
13
|
RCT_EXTERN_METHOD(prepUpload:(NSDictionary *)request withResolver:(RCTPromiseResolveBlock)resolve withRejecter:(RCTPromiseRejectBlock)reject)
|
|
7
14
|
RCT_EXTERN_METHOD(upload:(NSString *)url request:(NSDictionary *)request withResolver:(RCTPromiseResolveBlock)resolve withRejecter:(RCTPromiseRejectBlock)reject)
|
package/ios/RNSmileID.swift
CHANGED
|
@@ -1,16 +1,71 @@
|
|
|
1
|
-
import Combine
|
|
2
1
|
import SmileID
|
|
3
2
|
|
|
4
3
|
@objc(RNSmileID)
|
|
5
4
|
class RNSmileID: NSObject {
|
|
6
|
-
private var cancellables = Set<AnyCancellable>()
|
|
7
|
-
|
|
8
5
|
@objc(initialize:withResolver:withRejecter:)
|
|
9
6
|
func initialize(useSandBox: Bool, resolve: @escaping RCTPromiseResolveBlock, reject _: @escaping RCTPromiseRejectBlock) {
|
|
10
7
|
SmileID.initialize(useSandbox: useSandBox)
|
|
11
8
|
resolve(nil)
|
|
12
9
|
}
|
|
13
10
|
|
|
11
|
+
@objc(setEnvironment:withResolver:withRejecter:)
|
|
12
|
+
func setEnvironment(useSandBox: Bool, resolve: @escaping RCTPromiseResolveBlock, reject _: @escaping RCTPromiseRejectBlock) {
|
|
13
|
+
SmileID.setEnvironment(useSandbox: useSandBox)
|
|
14
|
+
resolve(nil)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@objc(setCallbackUrl:withResolver:withRejecter:)
|
|
18
|
+
func setCallbackUrl(callbackUrl: String, resolve: @escaping RCTPromiseResolveBlock, reject _: @escaping RCTPromiseRejectBlock) {
|
|
19
|
+
SmileID.setCallbackUrl(url: URL(string: callbackUrl))
|
|
20
|
+
resolve(nil)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@objc(setAllowOfflineMode:withResolver:withRejecter:)
|
|
24
|
+
func setAllowOfflineMode(allowOfflineMode: Bool, resolve: @escaping RCTPromiseResolveBlock, reject _: @escaping RCTPromiseRejectBlock) {
|
|
25
|
+
SmileID.setAllowOfflineMode(allowOfflineMode: allowOfflineMode)
|
|
26
|
+
resolve(nil)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@objc(submitJob:withResolver:withRejecter:)
|
|
30
|
+
func submitJob(jobId: String, resolve: @escaping RCTPromiseResolveBlock, reject : @escaping RCTPromiseRejectBlock) {
|
|
31
|
+
do {
|
|
32
|
+
try SmileID.submitJob(jobId: jobId)
|
|
33
|
+
resolve(nil)
|
|
34
|
+
} catch let error as NSError {
|
|
35
|
+
reject("Error", error.localizedDescription, error)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@objc(getSubmittedJobs:withRejecter:)
|
|
40
|
+
func getSubmittedJobs(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
41
|
+
do {
|
|
42
|
+
let jobs: [String] = SmileID.getUnsubmittedJobs()
|
|
43
|
+
resolve(jobs)
|
|
44
|
+
} catch let error as NSError {
|
|
45
|
+
reject("Error", error.localizedDescription, error)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@objc(getUnsubmittedJobs:withRejecter:)
|
|
50
|
+
func getUnsubmittedJobs(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
51
|
+
do {
|
|
52
|
+
let jobs: [String] = SmileID.getUnsubmittedJobs()
|
|
53
|
+
resolve(jobs)
|
|
54
|
+
} catch let error as NSError {
|
|
55
|
+
reject("Error", error.localizedDescription, error)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@objc(cleanup:withResolver:withRejecter:)
|
|
60
|
+
func cleanup(jobId: String, resolve: @escaping RCTPromiseResolveBlock, reject : @escaping RCTPromiseRejectBlock) {
|
|
61
|
+
do {
|
|
62
|
+
try SmileID.cleanup(jobId: jobId)
|
|
63
|
+
resolve(nil)
|
|
64
|
+
} catch let error as NSError {
|
|
65
|
+
reject("Error", error.localizedDescription, error)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
14
69
|
@objc(authenticate:withResolver:withRejecter:)
|
|
15
70
|
func authenticate(request: NSDictionary, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
16
71
|
guard let authenticationRequest = request.toAuthenticationRequest() else {
|
|
@@ -18,12 +73,14 @@ class RNSmileID: NSObject {
|
|
|
18
73
|
return
|
|
19
74
|
}
|
|
20
75
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}, receiveValue: { response in
|
|
76
|
+
Task {
|
|
77
|
+
do {
|
|
78
|
+
let response = try await SmileID.api.authenticate(request: authenticationRequest)
|
|
25
79
|
self.resolveResponse(response, resolve: resolve, reject: reject)
|
|
26
|
-
}
|
|
80
|
+
} catch {
|
|
81
|
+
reject("Error", error.localizedDescription, error)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
27
84
|
}
|
|
28
85
|
|
|
29
86
|
@objc(prepUpload:withResolver:withRejecter:)
|
|
@@ -33,11 +90,14 @@ class RNSmileID: NSObject {
|
|
|
33
90
|
return
|
|
34
91
|
}
|
|
35
92
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
93
|
+
Task {
|
|
94
|
+
do {
|
|
95
|
+
let response = try await SmileID.api.prepUpload(request: prepUploadRequest)
|
|
96
|
+
self.resolveResponse(response, resolve: resolve, reject: reject)
|
|
97
|
+
} catch {
|
|
98
|
+
reject("Error", error.localizedDescription, error)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
41
101
|
}
|
|
42
102
|
|
|
43
103
|
@objc(upload:request:withResolver:withRejecter:)
|
|
@@ -57,10 +117,14 @@ class RNSmileID: NSObject {
|
|
|
57
117
|
return
|
|
58
118
|
}
|
|
59
119
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
120
|
+
Task {
|
|
121
|
+
do {
|
|
122
|
+
try await SmileID.api.upload(zip: zipData, to: url)
|
|
123
|
+
resolve(nil)
|
|
124
|
+
} catch {
|
|
125
|
+
reject("Error", error.localizedDescription, error)
|
|
126
|
+
}
|
|
127
|
+
}
|
|
64
128
|
}
|
|
65
129
|
|
|
66
130
|
@objc(doEnhancedKyc:withResolver:withRejecter:)
|
|
@@ -111,23 +175,19 @@ class RNSmileID: NSObject {
|
|
|
111
175
|
signature: signature
|
|
112
176
|
)
|
|
113
177
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
case let .failure(error):
|
|
118
|
-
reject("Error", error.localizedDescription, error)
|
|
119
|
-
case .finished:
|
|
120
|
-
break
|
|
121
|
-
}
|
|
122
|
-
}, receiveValue: { response in
|
|
178
|
+
Task {
|
|
179
|
+
do {
|
|
180
|
+
let response = try await SmileID.api.doEnhancedKyc(request: request)
|
|
123
181
|
let encoder = JSONEncoder()
|
|
124
182
|
guard let jsonData = try? encoder.encode(response) else {
|
|
125
|
-
|
|
126
|
-
SmileIDError.unknown("doEnhancedKyc encoding error "))
|
|
127
|
-
return
|
|
183
|
+
throw SmileIDError.unknown("doEnhancedKyc encoding error")
|
|
128
184
|
}
|
|
129
|
-
|
|
130
|
-
|
|
185
|
+
// Assuming you have a method to convert response to a dictionary
|
|
186
|
+
resolve(["result": String(data: jsonData, encoding: .utf8)!])
|
|
187
|
+
} catch {
|
|
188
|
+
reject("Error", error.localizedDescription, error)
|
|
189
|
+
}
|
|
190
|
+
}
|
|
131
191
|
}
|
|
132
192
|
|
|
133
193
|
@objc(doEnhancedKycAsync:withResolver:withRejecter:)
|
|
@@ -178,23 +238,19 @@ class RNSmileID: NSObject {
|
|
|
178
238
|
signature: signature
|
|
179
239
|
)
|
|
180
240
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
return
|
|
195
|
-
}
|
|
196
|
-
resolve(["result": String(data: jsonData, encoding: .utf8)!]) // Assuming you have a method to convert response to a dictionary
|
|
197
|
-
}).store(in: &cancellables)
|
|
241
|
+
Task {
|
|
242
|
+
do {
|
|
243
|
+
let response = try await SmileID.api.doEnhancedKycAsync(request: request)
|
|
244
|
+
let encoder = JSONEncoder()
|
|
245
|
+
guard let jsonData = try? encoder.encode(response) else {
|
|
246
|
+
throw SmileIDError.unknown("doEnhancedKyc encoding error")
|
|
247
|
+
}
|
|
248
|
+
// Assuming you have a method to convert response to a dictionary
|
|
249
|
+
resolve(["result": String(data: jsonData, encoding: .utf8)!])
|
|
250
|
+
} catch {
|
|
251
|
+
reject("Error", error.localizedDescription, error)
|
|
252
|
+
}
|
|
253
|
+
}
|
|
198
254
|
}
|
|
199
255
|
|
|
200
256
|
@objc(getSmartSelfieJobStatus:withResolver:withRejecter:)
|
|
@@ -224,11 +280,14 @@ class RNSmileID: NSObject {
|
|
|
224
280
|
return
|
|
225
281
|
}
|
|
226
282
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
283
|
+
Task {
|
|
284
|
+
do {
|
|
285
|
+
let response = try await SmileID.api.getProductsConfig(request: productsConfigRequest)
|
|
286
|
+
self.resolveResponse(response, resolve: resolve, reject: reject)
|
|
287
|
+
} catch {
|
|
288
|
+
reject("Error", error.localizedDescription, error)
|
|
289
|
+
}
|
|
290
|
+
}
|
|
232
291
|
}
|
|
233
292
|
|
|
234
293
|
@objc(getValidDocuments:withResolver:withRejecter:)
|
|
@@ -238,18 +297,26 @@ class RNSmileID: NSObject {
|
|
|
238
297
|
return
|
|
239
298
|
}
|
|
240
299
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
300
|
+
Task {
|
|
301
|
+
do {
|
|
302
|
+
let response = try await SmileID.api.getValidDocuments(request: validDocumentsRequest)
|
|
303
|
+
self.resolveResponse(response, resolve: resolve, reject: reject)
|
|
304
|
+
} catch {
|
|
305
|
+
reject("Error", error.localizedDescription, error)
|
|
306
|
+
}
|
|
307
|
+
}
|
|
245
308
|
}
|
|
246
309
|
|
|
247
310
|
@objc(getServicesWithResolver:withRejecter:)
|
|
248
311
|
func getServices(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
312
|
+
Task {
|
|
313
|
+
do {
|
|
314
|
+
let response = try await SmileID.api.getServices()
|
|
315
|
+
self.resolveResponse(response, resolve: resolve, reject: reject)
|
|
316
|
+
} catch {
|
|
317
|
+
reject("Error", error.localizedDescription, error)
|
|
318
|
+
}
|
|
319
|
+
}
|
|
253
320
|
}
|
|
254
321
|
|
|
255
322
|
@objc(getJobStatus:withResolver:withRejecter:)
|
|
@@ -259,10 +326,14 @@ class RNSmileID: NSObject {
|
|
|
259
326
|
return
|
|
260
327
|
}
|
|
261
328
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
329
|
+
Task {
|
|
330
|
+
do {
|
|
331
|
+
let response = try await SmileID.api.getJobStatus(request: jobStatusRequest)
|
|
332
|
+
self.resolveResponse(response, resolve: resolve, reject: reject)
|
|
333
|
+
} catch {
|
|
334
|
+
reject("Error", error.localizedDescription, error)
|
|
335
|
+
}
|
|
336
|
+
}
|
|
266
337
|
}
|
|
267
338
|
|
|
268
339
|
@objc(pollSmartSelfieJobStatus:withResolver:withRejecter:)
|
|
@@ -374,7 +445,7 @@ class RNSmileID: NSObject {
|
|
|
374
445
|
}
|
|
375
446
|
|
|
376
447
|
func pollJobStatus<RequestType, ResponseType: Encodable>(
|
|
377
|
-
apiCall: @escaping (RequestType, TimeInterval, Int) ->
|
|
448
|
+
apiCall: @escaping (RequestType, TimeInterval, Int) async throws -> ResponseType,
|
|
378
449
|
request: RequestType,
|
|
379
450
|
interval: Int64,
|
|
380
451
|
numAttempts: Int64,
|
|
@@ -387,18 +458,14 @@ class RNSmileID: NSObject {
|
|
|
387
458
|
return
|
|
388
459
|
}
|
|
389
460
|
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
}, receiveValue: { [self] response in
|
|
399
|
-
resolveResponse(response, resolve: resolve, reject: reject)
|
|
400
|
-
})
|
|
401
|
-
.store(in: &cancellables)
|
|
461
|
+
Task {
|
|
462
|
+
do {
|
|
463
|
+
let response = try await apiCall(request, timeInterval, numAttemptsInt)
|
|
464
|
+
self.resolveResponse(response, resolve: resolve, reject: reject)
|
|
465
|
+
} catch {
|
|
466
|
+
reject("ApiCallFailure", "API call failed with error: \(error.localizedDescription)", error)
|
|
467
|
+
}
|
|
468
|
+
}
|
|
402
469
|
}
|
|
403
470
|
|
|
404
471
|
|
|
@@ -407,15 +474,6 @@ class RNSmileID: NSObject {
|
|
|
407
474
|
return TimeInterval(seconds)
|
|
408
475
|
}
|
|
409
476
|
|
|
410
|
-
private func handleCompletion(_ completion: Subscribers.Completion<Error>, reject: @escaping RCTPromiseRejectBlock) {
|
|
411
|
-
switch completion {
|
|
412
|
-
case let .failure(error):
|
|
413
|
-
reject("Error", error.localizedDescription, error)
|
|
414
|
-
case .finished:
|
|
415
|
-
break
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
|
|
419
477
|
private func resolveResponse<T: Encodable>(_ response: T, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
420
478
|
let encoder = JSONEncoder()
|
|
421
479
|
guard let jsonData = try? encoder.encode(response) else {
|