@socure-inc/docv-react-native 3.0.0

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/License.txt ADDED
@@ -0,0 +1,33 @@
1
+ Socure's Software Development Kit (SDK) LICENSE AGREEMENT
2
+
3
+ This Software Development Kit (“SDK”) License Agreement (“Agreement”) is between you (both the individual downloading the SDK and any legal entity on behalf of which such individual is acting) (“You” or “Your”) and Socure Inc. (“Socure”).
4
+ IT IS IMPORTANT THAT YOU READ CAREFULLY AND UNDERSTAND THIS AGREEMENT. BY CLICKING THE “I ACCEPT” BUTTON OR AN EQUIVALENT INDICATOR OR BY DOWNLOADING, INSTALLING OR USING THE SDK OR THE DOCUMENTATION, YOU AGREE TO BE BOUND BY THIS AGREEMENT. IF YOU DO NOT AGREE TO BE BOUND BY THIS AGREEMENT, YOU WILL NOT BE PERMITTED TO (AND YOU WILL HAVE NO RIGHT TO) DOWNLOAD, INSTALL OR USE THE SDK OR THE DOCUMENTATION.
5
+ 1. DEFINITIONS
6
+ 1.2 “Documentation” means the materials made available to You in connection with the Software by or on behalf of Socure pursuant to this Agreement.
7
+ 1.3 “Master Service Agreement” means the underlying agreement between You and Socure outlining your use of any and all Socure products and services.
8
+ 1.4 “Software” means all of the software included in the software development kit made available to You by or on behalf of Socure pursuant to this Agreement, including but not limited to sample source code, code snippets, software tools, code libraries, sample applications, Documentation and any upgrades, modified versions, updates, and/or additions thereto, if any, made available to You by or on behalf of Socure pursuant to this Agreement.
9
+ 2. GRANT OF LICENSE; RESTRICTIONS
10
+ 2.1 Limited License. Subject to and conditioned upon Your compliance with the terms of this Agreement, Socure hereby grants to You a limited, revocable, non-exclusive, non-transferable, royalty-free license during the term of this Agreement to use the Software, pursuant to the terms of Your Master Service Agreement with Socure. If you do not have a Master Service Agreement in place with Socure, you are prohibited from downloading or using the Software or the SDK.
11
+ 2.2 Restrictions. You shall not (and shall have no right to): (a) make or distribute copies of the Software or the Documentation, in whole or in part, except as expressly permitted pursuant to Section 2.1; (b) alter or remove any copyright, trademark, trade name or other proprietary notices, legends, symbols or labels appearing on or in the Software or Documentation; (c) sublicense (or purport to sublicense) the Software or the Documentation, in whole or in part, to any third party except as expressly permitted pursuant to Section 2.1; (d) engage in any activity with the Software, including the development or distribution of an application, that interferes with, disrupts, damages, or accesses in an unauthorized manner the platform, servers, or systems of Socure, any of its affiliates, or any third party; (e) otherwise use or exploit the Software or the Documentation for any purpose other than as expressly permitted in your Master Service Agreement.
12
+ 2.3 Ownership. You acknowledge and agree that all right, title and interest in and to the Software and Documentation shall, at all times, be and remain the exclusive property of Socure and that You do not have or acquire any rights, express or implied, in the Software or Documentation.
13
+ 2.4 No Support. Socure has no obligation to provide support, maintenance, upgrades, modifications or new releases of the Software.
14
+ 2.5 Use. (a) You represent, warrant and agree to use the Software and write Applications only for purposes permitted by (i) this Agreement; (ii) your Master Service Agreement (iii) applicable law and regulation; and (iv) generally accepted practices or guidelines in the relevant jurisdictions. (b) You represent, warrant and agree that You are solely responsible for (and that neither Socure nor its affiliates have any responsibility to You or to any third party for): (i) any data, content, or resources that You obtain, transmit or display through the use of Software; and (ii) any breach of Your obligations under this Agreement, any applicable third party license, or any applicable law or regulation, and for the consequences of any such breach.
15
+ 3. WARRANTY DISCLAIMER; LIMITATION OF LIABILITY
16
+ 3.1 Disclaimer. THE SOFTWARE AND THE DOCUMENTATION ARE PROVIDED ON AN “AS IS” AND “AS AVAILABLE” BASIS WITH NO WARRANTY. YOU AGREE THAT YOUR USE OF THE SOFTWARE AND THE DOCUMENTATION IS AT YOUR SOLE RISK AND YOU ARE SOLELY RESPONSIBLE FOR ANY DAMAGE TO YOUR COMPUTER SYSTEM OR OTHER DEVICE OR LOSS OF DATA THAT RESULTS FROM SUCH USE. TO THE FULLEST EXTENT PERMISSIBLE UNDER APPLICABLE LAW, SOCURE AND ITS AFFILIATES EXPRESSLY DISCLAIM ALL WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED, WITH RESPECT TO THE SOFTWARE AND THE DOCUMENTATION, INCLUDING ALL WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, SATISFACTORY QUALITY, ACCURACY, TITLE AND NON-INFRINGEMENT, AND ANY WARRANTIES THAT MAY ARISE OUT OF COURSE OF PERFORMANCE, COURSE OF DEALING OR USAGE OF TRADE. NEITHER SOCURE NOR ITS AFFILIATES WARRANT THAT THE FUNCTIONS OR INFORMATION CONTAINED IN THE SOFTWARE OR THE DOCUMENTATION WILL MEET ANY REQUIREMENTS OR NEEDS YOU MAY HAVE, OR THAT THE SOFTWARE OR DOCUMENTATION WILL OPERATE ERROR FREE, OR THAT THE SOFTWARE OR DOCUMENTATION IS COMPATIBLE WITH ANY PARTICULAR OPERATING SYSTEM.
17
+ 3.2 Limitation of Liability. IN NO EVENT SHALL SOCURE OR ITS AFFILIATES BE LIABLE FOR ANY INDIRECT, INCIDENTAL, SPECIAL, CONSEQUENTIAL OR PUNITIVE DAMAGES, OR DAMAGES FOR LOSS OF PROFITS, REVENUE, BUSINESS, SAVINGS, DATA, USE OR COST OF SUBSTITUTE PROCUREMENT, INCURRED BY YOU OR ANY THIRD PARTY, WHETHER IN AN ACTION IN CONTRACT OR TORT, EVEN IF SOCURE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES OR IF SUCH DAMAGES ARE FORESEEABLE. IN NO EVENT SHALL THE ENTIRE LIABILITY OF SOCURE AND AFFILIATES ARISING FROM OR RELATING TO THIS AGREEMENT OR THE SUBJECT MATTER HEREOF EXCEED THE FEES PAID BY YOU FOR THE SOFTWARE UNDER THIS AGREEMENT. THE PARTIES ACKNOWLEDGE THAT THE LIMITATIONS OF LIABILITY IN THIS SECTION 3.2 AND IN THE OTHER PROVISIONS OF THIS AGREEMENT AND THE ALLOCATION OF RISK HEREIN ARE AN ESSENTIAL ELEMENT OF THE BARGAIN BETWEEN THE PARTIES, WITHOUT WHICH SOCURE WOULD NOT HAVE ENTERED INTO THIS AGREEMENT.
18
+ 4. INDEMNIFICATION
19
+ You shall indemnify, hold harmless and, at Socure’s request, defend Socure and its affiliates and their officers, directors, employees, and agents from and against any claim, suit or proceeding, and any associated liabilities, costs, damages and expenses, including reasonable attorneys’ fees, that arise out of relate to: (i) Your use or distribution of the Software or the Documentation (or any portion thereof), including, but not limited to, any allegation that any such use or distribution infringes, misappropriates or otherwise violates any intellectual property (including, without limitation, copyright, patent, and trademark), privacy, publicity or other rights of any third party, or has caused the death or injury of any person or damage to any property; (ii) Your alleged or actual breach of this Agreement; (iii) the alleged or actual breach of this Agreement by any party to whom you have provided the Software or the Documentation or (iii) Your alleged or actual violation of or non-compliance with any applicable laws, legislation, policies, rules, regulations or governmental requirements (including, without limitation, any laws, legislation, policies, rules, regulations or governmental requirements related to privacy and data collection).
20
+ 5. TERMINATION
21
+ This Agreement and the licenses granted to you herein are effective until terminated. Socure may terminate this Agreement and the licenses granted to You at any time. Upon termination of this Agreement, You shall cease all use of the Software and the Documentation, return to Socure or destroy all copies of the Software and Documentation and related materials in Your possession, and so certify to Socure. Except for the license to You granted herein, the terms of this Agreement shall survive termination.
22
+ 6. CONFIDENTIAL INFORMATION
23
+ 6.1 You hereby agree (i) to hold Socure’s Confidential Information in strict confidence and to take reasonable precautions to protect such Confidential Information (including, without limitation, all precautions You employ with respect to Your own confidential materials), (ii) not to divulge any such Confidential Information to any third person; (iii) not to make any use whatsoever at any time of such Confidential Information except as strictly licensed hereunder, (iv) not to remove or export from the United States or re-export any such Confidential Information or any direct product thereof, except in compliance with, and with all licenses and approvals required under applicable U.S. and foreign export laws and regulations, including, without limitation, those of the U.S. Department of Commerce.
24
+ “Confidential Information” shall mean any data or information, oral or written, treated as confidential that relates to Socure’s past, present, or future research, development or business activities, including without limitation any unannounced products and services, any information relating to services, developments, inventions, processes, plans, financial information, customer data, revenue, transaction volume, forecasts, projections, application programming interfaces, Software and Documentation.
25
+ 7. General Terms
26
+ 7.1 Law. This Agreement and all matters arising out of or relating to this Agreement shall be governed by the laws of the State of New York without giving effect to any choice of law rule. This Agreement shall not be governed by the United Nations Convention on Contracts for the International Sales of Goods, the application of which is expressly excluded. In the event of any controversy, claim or dispute between the parties arising out of or relating to this Agreement, such controversy, claim or dispute shall be resolved in the state or federal courts in New York City, New York, and the parties hereby irrevocably consent to the jurisdiction and venue of such courts.
27
+ 7.2 Severability and Waiver. If any provision of this Agreement is held to be illegal, invalid or otherwise unenforceable, such provision shall be enforced to the extent possible consistent with the stated intention of the parties, or, if incapable of such enforcement, shall be deemed to be severed and deleted from this Agreement, while the remainder of this Agreement shall continue in full force and effect. The waiver by either party of any default or breach of this Agreement shall not constitute a waiver of any other or subsequent default or breach.
28
+ 7.3 No Assignment. You may not assign, sell, transfer, delegate or otherwise dispose of, whether voluntarily or involuntarily, by operation of law or otherwise, this Agreement or any rights or obligations under this Agreement without the prior written consent of Socure, which may be withheld in Socure’s sole discretion. Any purported assignment, transfer or delegation by You shall be null and void. Subject to the foregoing, this Agreement shall be binding upon and shall inure to the benefit of the parties and their respective successors and assigns.
29
+ 7.4 Export Administration. You shall comply fully with all relevant export laws and regulations of the United States, including, without limitation, the U.S. Export Administration Regulations (collectively “Export Controls”). Without limiting the generality of the foregoing, You shall not, and You shall require Your representatives not to, export, direct or transfer the Software or the Documentation, or any direct product thereof, to any destination, person or entity restricted or prohibited by the Export Controls.
30
+ 7.5 Privacy. In order to continually innovate and improve the Software, You understand and agree that Socure may collect certain usage statistics including but not limited to a unique identifier, associated IP address, version number of software, and information on which tools and/or services in the Software are being used and how they are being used.
31
+ 7.6 Headings. The headings to the Sections and Subsections of this Agreement are included merely for convenience of reference and shall not affect the meaning of the language included therein.
32
+ 7.7 Entire Agreement; Amendments. This Agreement in conjunction with Your Master Service Agreement constitutes the entire agreement between the parties and supersedes all prior or contemporaneous agreements or representations, written or oral, concerning the subject matter of this Agreement, including any agreement or terms that may exist between You and GitHub. Socure may make changes to this Agreement, Software or Documentation in its sole discretion. When these changes are made, Socure will make a new version of the Agreement, Software or Documentation available on the website where the Software is available. This Agreement may not be modified or amended by You except in a writing signed by a duly authorized representative of each party. You acknowledge and agree that Socure has not made any representations, warranties or agreements of any kind, except as expressly set forth herein.
33
+ BY CLICKING “I ACCEPT,” “I AGREE” OR AN EQUIVALENT INDICATOR OR BY DOWNLOADING, INSTALLING OR USING THE SOFTWARE OR THE DOCUMENTATION, YOU ACKNOWLEDGE AND AGREE THAT (1) YOU HAVE READ AND REVIEWED THIS AGREEMENT IN ITS ENTIRETY, (2) YOU AGREE TO BE BOUND BY THIS AGREEMENT, (3) YOU HAVE THE POWER, AUTHORITY AND LEGAL RIGHT TO ENTER INTO THIS AGREEMENT ON BEHALF OF YOU AND, (4) THIS AGREEMENT CONSTITUTES BINDING AND ENFORCEABLE OBLIGATIONS OF YOU.
package/README.md ADDED
@@ -0,0 +1,317 @@
1
+ # Predictive DocV SDK v3 React Native
2
+
3
+ The Predictive Document Verification (DocV) SDK v3 for React Native is a React Native wrapper that allows you to use the DocV SDK for Android and iOS in your React Native application.
4
+
5
+ ## Minimum Requirements
6
+
7
+ **React Native**
8
+
9
+ - React Native CLI. See the [React Native docs](https://reactnative.dev/docs/environment-setup) for instructions on how to set up your development environment.
10
+
11
+ **iOS**
12
+
13
+ - Support for iOS 13 and later
14
+ - Xcode version 13+
15
+
16
+ **Android**
17
+
18
+ - Android SDK Version 22 (OS Version 5.1) and later
19
+ - Android SDK is compiled with `compileSdkVersion` 32 and Java 11
20
+
21
+ ## Getting started
22
+
23
+ To get started, complete the steps in the following sections:
24
+
25
+ - [Install the React Native wrapper with NPM](#install-the-react-native-wrapper-with-npm)
26
+ - [Configure your iOS or Android app](#configure-your-ios-or-android-app)
27
+ - [Import and launch the SDK](#import-and-launch-the-sdk)
28
+
29
+ ## Install the React Native wrapper with NPM
30
+
31
+ In your React Native project, install the DocV React Native wrapper by running the following NPM command:
32
+
33
+ ```
34
+ npm install @socure-inc/docv-react-native
35
+ ```
36
+
37
+ ## Configure your iOS or Android app
38
+
39
+ Your React Native project needs to access the DocV iOS or Android SDKs through the React Native wrapper. Follow the instructions in the drop down menus below to integrate the DocV SDK into your iOS or Android app.
40
+
41
+ <br />
42
+
43
+ <details>
44
+ <summary><b>Integrate with the DocV iOS SDK</b></summary>
45
+
46
+ <br />
47
+
48
+ ### Configure your iOS app
49
+
50
+ For the iOS app, you can install the DocV iOS SDK into your project using Cocoapods. If you do not already have the CocoaPods tool installed, see the [CocoaPods Getting Started guide](https://guides.cocoapods.org/using/getting-started.html#installation).
51
+
52
+ #### Add project dependencies
53
+
54
+ In your root project folder, open your Podfile with a text editor and specify the following project dependencies:
55
+
56
+ - Replace the deployment target with `platform :ios, '13.0'`.
57
+ - Add the line pod `'socure-docv-react-native', :path => '../node_modules/@socure-inc/docv-react-native'`
58
+
59
+ Once completed, your Podfile should look like the following example:
60
+
61
+ ```swift {4,36}
62
+ require_relative '../node_modules/react-native/scripts/react_native_pods'
63
+ require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
64
+
65
+ platform :ios, '13.0'
66
+ install! 'cocoapods', :deterministic_uuids => false
67
+
68
+ production = ENV["PRODUCTION"] == "1"
69
+
70
+ target 'SocureDocVDemo' do
71
+ config = use_native_modules!
72
+
73
+ # Flags change depending on the env values.
74
+ flags = get_default_flags()
75
+
76
+ use_react_native!(
77
+ :path => config[:reactNativePath],
78
+ # to enable hermes on iOS, change `false` to `true` and then install pods
79
+ :production => production,
80
+ :hermes_enabled => flags[:hermes_enabled],
81
+ :fabric_enabled => flags[:fabric_enabled],
82
+ :flipper_configuration => FlipperConfiguration.enabled,
83
+ # An absolute path to your application root.
84
+ :app_path => "#{Pod::Config.instance.installation_root}/.."
85
+ )
86
+
87
+ target 'SocureDocVDemoTests' do
88
+ inherit! :complete
89
+ # Pods for testing
90
+ end
91
+
92
+ post_install do |installer|
93
+ react_native_post_install(installer)
94
+ __apply_Xcode_12_5_M1_post_install_workaround(installer)
95
+ end
96
+
97
+ pod 'socure-docv-react-native', :path => '../node_modules/@socure-inc/docv-react-native'
98
+
99
+ end
100
+ ```
101
+
102
+ #### Install the dependencies
103
+
104
+ Change the location of your working directory to the `iOS` folder:
105
+
106
+ ```
107
+ cd ios
108
+ ```
109
+
110
+ Install the Cocoapods dependencies by running the following command:
111
+
112
+ ```
113
+ pod install
114
+ ```
115
+
116
+ #### Use the CocoaPods-generated `.xcworkspace` file
117
+
118
+ The CocoaPods installation command generates a `.xcworkspace` file with all the dependencies configured. To continue with the installation, complete the following:
119
+
120
+ - Close Xcode and then open your project's `.xcworkspace` file to launch Xcode. From now on, use the `.xcworkspace` to open your project.
121
+ - Check that your deployment target is set to iOS 13 or later.
122
+
123
+ #### Request camera permissions
124
+
125
+ The DocV iOS SDK requires a device's camera permission to capture identity documents. Upon the first invocation of the SDK, the app will request camera permission from the consumer. If the app does not already use the camera, you must add the following to the app’s `Info.plist file`:
126
+
127
+ | Key | Type | Value |
128
+ |------------------------------------|--------|---------------------------------------------------------------------------------------------|
129
+ | Privacy - Camera Usage Description | String | "This application requires use of your camera in order to capture your identity documents." |
130
+
131
+
132
+ > **Note:** We recommend you check for camera permission before calling the SocureDocV SDK’s launch API. 
133
+
134
+ ### Run the app
135
+
136
+ Using the command line, go to your root project folder and enter the following command to run the app:
137
+
138
+ ```
139
+ "react-native run-ios"
140
+ ```
141
+
142
+ </details>
143
+
144
+ <details>
145
+ <summary><b>Integrate with the DocV Android SDK</b></summary>
146
+
147
+ <br />
148
+
149
+ ### Configure your Android app
150
+
151
+ For the Android app, add your project dependencies by going to the module level `build.gradle` file and making sure the `minSdkVersion` is set to at least 22 and the `compileSdkVersion` is set to at least 32.
152
+
153
+ ```kotlin {5,6}
154
+ buildscript {
155
+ .....
156
+ ext {
157
+ ....
158
+ minSdkVersion = 22
159
+ compileSdkVersion = 32
160
+ .....
161
+ }
162
+ }
163
+ ```
164
+
165
+ ### Camera permissions
166
+
167
+ The DocV Android SDK requires camera permission to capture identity documents. Upon the first invocation of the SDK, your app will request camera permission from the user.
168
+
169
+ > **Note:** We recommend you check for camera permissions before calling the Socure DocV SDK’s launch API.
170
+
171
+ #### Required permissions
172
+
173
+ Ensure that your app manifest has been set up properly to request the following required permissions:
174
+
175
+ ```
176
+ <uses-feature android:name="android.hardware.camera" />
177
+
178
+ <!-- Declare permissions -->
179
+ <uses-permission android:name="android.permission.CAMERA" />
180
+ <uses-permission android:name="android.permission.INTERNET" />
181
+ <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
182
+ ```
183
+
184
+ ## Run the app
185
+
186
+ From the command line, go to your root project folder and enter the following command to run the app:
187
+
188
+ ```
189
+ react-native run-android
190
+ ```
191
+
192
+ </details>
193
+
194
+ <br />
195
+
196
+ ## Import and launch the SDK
197
+
198
+ After you have installed the DocV SDK React Native wrapper using NPM and configured your iOS or Android app, add the following code to your `App.js` file to import `launchSocureDocV`:
199
+
200
+ ```jsx
201
+ import { launchSocureDocV } from "@socure-inc/docv-react-native"
202
+ ```
203
+
204
+ To launch the Socure DocV SDK, specify your SDK key and call the `launchSocureDocV` launch function:
205
+
206
+ ```jsx
207
+ launchSocureDocV("SOCURE_SDK_KEY", flow, onSuccess, onError);
208
+ ```
209
+
210
+ ## How it works
211
+
212
+ Your React Native application initializes and communicates with the DocV SDK through the React Native wrapper using the `launchSocureDocV` instance. The `launchSocureDocV` function also includes two callback functions, one for `onSuccess` and one for `onError`. See [Response callbacks](#response-callbacks) below for more information.
213
+
214
+ The following table lists the available `launchSocureDocV` properties:
215
+
216
+ | Argument | Description |
217
+ | ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
218
+ | `socure_sdk_key` | The unique SDK key obtained from Admin Dashboard. For more information on SDK keys, see the [Getting Started](https://developer.socure.com/docs/) article. |
219
+ | `flow` | An optional JSON string or null value that specifies a custom flow. The `FLOW_NAME` value specifies the name of the flow (created in Admin Dashboard) that the DocV SDK should use. <br /> <br />`JSON.stringify({flow: {name: “FLOW_NAME”}})` <br /> <br />If the value is `null`, the DocV SDK will fetch the default flow from Admin Dashboard. | | |
220
+ | `onSuccess` | A callback function that notifies you when the flow completes successfully. | | |
221
+ | `onError` | A callback function that notifies you when the flow fails. | | |
222
+
223
+
224
+ ## Response callbacks
225
+
226
+ Your app can receive a response callback from the Socure DocV SDK when the flow completes successfully or returns with an error using the `onSuccess` and `onError` callback functions.
227
+
228
+ ### `onSuccess` response
229
+ When the consumer successfully completes the flow and the captured images are uploaded, the `onSuccess` callback receives the ScannedData object which contains session information and the extracted data. The table below lists the available `ScannedData` properties.
230
+
231
+ | Result Field | Type | Description |
232
+ |----------------|-------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
233
+ | `docUUID` | string | The UUID for the uploaded scanned images. |
234
+ | `sessionId` | string | The session ID for the scan session. |
235
+ | `extractedData` | JSON object | Contains extractedInfo from the barcode or MRZ. |
236
+ | `captureData` | JSON object | The mapped capture type for every scan. <br /> Possible keys are: `lic_front`, `lic_back`, `passport`, `selfie` <br /> Possible values can be `manual` or `auto` |
237
+ | `capturedImages` | JSON object | The mapped image data of captured images. <br /> Possible keys are: `lic_front`, `lic_back`, `passport`, `selfie` <br /> Value will be a base64 image string <br />**Note**: Prefix `data:image/png;base64,` while using base64 string. |
238
+
239
+ #### Sample `onSuccess` response
240
+ ```json
241
+ {
242
+ "docUUID": "UUID for the uploaded scanned images",
243
+ "sessionId": "Session ID for the particular scan session",
244
+ "extractedData": {
245
+ "address": "123 TAYLOR AVE",
246
+ "issueDate": "09282007",
247
+ "parsedAddress": {
248
+ "city": "SAN BRUNO",
249
+ "country": "USA",
250
+ "physicalAddress": "123 TAYLOR AVE",
251
+ "physicalAddress2": "SAN BRUNO",
252
+ "postalCode": "940660000",
253
+ "state": "CA"
254
+ },
255
+ "dob": "07221977",
256
+ "documentNumber": "D12345",
257
+ "expirationDate": "07222022",
258
+ "firstName": "SAM",
259
+ "fullName": "SAM SOTO",
260
+ "type": "barcode"
261
+ },
262
+ "captureData": {
263
+ "lic_front": "auto",
264
+ "lic_back": "auto",
265
+ "passport": "auto",
266
+ "selfie": "manual"
267
+ },
268
+ "capturedImages": {
269
+ "lic_front": "base64 Image as String",
270
+ "lic_back": "base64 Image as String",
271
+ "selfie": "base64 Image as String"
272
+ }
273
+ }
274
+ ```
275
+
276
+ ### `onError` response
277
+
278
+ If the consumer exits the flow without completing it or the SDK encounters an error, the `onError` callback receives the `ScanError` object which contains session information and the error. The table below lists the available `ScanError` properties.
279
+
280
+ | Error Field | Type | Description |
281
+ |----------------|-------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
282
+ | `capturedImages` | JSON object | The mapped image data of captured images (if available). <br /> Possible keys are: `lic_front`, `lic_back`, `passport`, `selfie` <br /> Value will be a base64 image string <br /> **Note**: Prefix `data:image/png;base64,` while using base64 string. |
283
+ | `errorMessage` | string | The error code description. |
284
+ | `sessionId` | string | The session ID for the particular scan session. |
285
+ | `statusCode` | string | The error code returned by Socure DocV SDK. |
286
+
287
+ #### Sample `onError` response
288
+ ```json
289
+ {
290
+ "capturedImages": {
291
+ "passport": "base64 Image as String"
292
+ },
293
+ "errorMessage": "Scan canceled by the user",
294
+ "sessionId": "2a55f9-42bgfa-4fb3-9gf32e-6a6fec5",
295
+ "statusCode": "7104"
296
+ }
297
+ ```
298
+
299
+ ### Error codes
300
+
301
+ The following table lists the errors that can be returned by Socure DocV SDK:
302
+
303
+ | Error Code | Error Description (string) |
304
+ | ---------- | ------------------------------------------------------- |
305
+ | `7011` | `Invalid key` |
306
+ | `7021` | `Failed to initiate the session ` |
307
+ | `7014` | `Session expired ` |
308
+ | `7101` | `Empty key ` |
309
+ | `7103` | `No internet connection ` |
310
+ | `7102` | `Do not have the required permissions to open the camera` |
311
+ | `7022` | `Failed to upload the documents ` |
312
+ | `7104` | `Scan canceled by the user` |
313
+ | `7106` | `Camera error` |
314
+ | `7107` | `Unknown error` |
315
+ | `7108` | `Camera resolution doesn't match the minimum requirement` |
316
+ | `7109` | `Invalid config data` |
317
+ | `7110` | `Consent declined` |
@@ -0,0 +1,147 @@
1
+ buildscript {
2
+ // Buildscript is evaluated before everything else so we can't use getExtOrDefault
3
+ def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : project.properties['SocureDocVReactNative_kotlinVersion']
4
+
5
+ repositories {
6
+ google()
7
+ mavenCentral()
8
+ }
9
+
10
+ dependencies {
11
+ classpath 'com.android.tools.build:gradle:3.5.3'
12
+ // noinspection DifferentKotlinGradleVersion
13
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
14
+ }
15
+ }
16
+
17
+ def isNewArchitectureEnabled() {
18
+ return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
19
+ }
20
+
21
+ apply plugin: 'com.android.library'
22
+ apply plugin: 'kotlin-android'
23
+
24
+ if (isNewArchitectureEnabled()) {
25
+ apply plugin: 'com.facebook.react'
26
+ }
27
+
28
+ def getExtOrDefault(name) {
29
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['SocureDocVReactNative_' + name]
30
+ }
31
+
32
+ def getExtOrIntegerDefault(name) {
33
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['SocureDocVReactNative_' + name]).toInteger()
34
+ }
35
+
36
+ android {
37
+ compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')
38
+
39
+ defaultConfig {
40
+ minSdkVersion getExtOrIntegerDefault('minSdkVersion')
41
+ targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
42
+ buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
43
+ }
44
+ buildTypes {
45
+ release {
46
+ minifyEnabled false
47
+ }
48
+ }
49
+
50
+ lintOptions {
51
+ disable 'GradleCompatible'
52
+ }
53
+
54
+ compileOptions {
55
+ sourceCompatibility JavaVersion.VERSION_11
56
+ targetCompatibility JavaVersion.VERSION_11
57
+ }
58
+ }
59
+
60
+ repositories {
61
+ mavenCentral()
62
+ google()
63
+ maven { url "https://jitpack.io" }
64
+
65
+ def found = false
66
+ def defaultDir = null
67
+ def androidSourcesName = 'React Native sources'
68
+
69
+ if (rootProject.ext.has('reactNativeAndroidRoot')) {
70
+ defaultDir = rootProject.ext.get('reactNativeAndroidRoot')
71
+ } else {
72
+ defaultDir = new File(
73
+ projectDir,
74
+ '/../../../node_modules/react-native/android'
75
+ )
76
+ }
77
+
78
+ if (defaultDir.exists()) {
79
+ maven {
80
+ url defaultDir.toString()
81
+ name androidSourcesName
82
+ }
83
+
84
+ logger.info(":${project.name}:reactNativeAndroidRoot ${defaultDir.canonicalPath}")
85
+ found = true
86
+ } else {
87
+ def parentDir = rootProject.projectDir
88
+
89
+ 1.upto(5, {
90
+ if (found) return true
91
+ parentDir = parentDir.parentFile
92
+
93
+ def androidSourcesDir = new File(
94
+ parentDir,
95
+ 'node_modules/react-native'
96
+ )
97
+
98
+ def androidPrebuiltBinaryDir = new File(
99
+ parentDir,
100
+ 'node_modules/react-native/android'
101
+ )
102
+
103
+ if (androidPrebuiltBinaryDir.exists()) {
104
+ maven {
105
+ url androidPrebuiltBinaryDir.toString()
106
+ name androidSourcesName
107
+ }
108
+
109
+ logger.info(":${project.name}:reactNativeAndroidRoot ${androidPrebuiltBinaryDir.canonicalPath}")
110
+ found = true
111
+ } else if (androidSourcesDir.exists()) {
112
+ maven {
113
+ url androidSourcesDir.toString()
114
+ name androidSourcesName
115
+ }
116
+
117
+ logger.info(":${project.name}:reactNativeAndroidRoot ${androidSourcesDir.canonicalPath}")
118
+ found = true
119
+ }
120
+ })
121
+ }
122
+
123
+ if (!found) {
124
+ throw new GradleException(
125
+ "${project.name}: unable to locate React Native android sources. " +
126
+ "Ensure you have you installed React Native as a dependency in your project and try again."
127
+ )
128
+ }
129
+ }
130
+
131
+ def kotlin_version = getExtOrDefault('kotlinVersion')
132
+
133
+ dependencies {
134
+ //noinspection GradleDynamicVersion
135
+ implementation "com.facebook.react:react-native:+"
136
+ implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
137
+ implementation "com.github.socure-inc:socure-docv:3.0.1"
138
+ // From node_modules
139
+ }
140
+
141
+ if (isNewArchitectureEnabled()) {
142
+ react {
143
+ jsRootDir = file("../src/")
144
+ libraryName = "SocureDocVReactNative"
145
+ codegenJavaPackageName = "com.socure.docv.reactnative"
146
+ }
147
+ }
@@ -0,0 +1,5 @@
1
+ distributionBase=GRADLE_USER_HOME
2
+ distributionPath=wrapper/dists
3
+ distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-bin.zip
4
+ zipStoreBase=GRADLE_USER_HOME
5
+ zipStorePath=wrapper/dists
@@ -0,0 +1,5 @@
1
+ SocureDocVReactNative_kotlinVersion=1.7.0
2
+ SocureDocVReactNative_minSdkVersion=22
3
+ SocureDocVReactNative_targetSdkVersion=32
4
+ SocureDocVReactNative_compileSdkVersion=32
5
+ SocureDocVReactNative_ndkversion=21.4.7075529
@@ -0,0 +1,185 @@
1
+ #!/usr/bin/env sh
2
+
3
+ #
4
+ # Copyright 2015 the original author or authors.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # https://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ ##############################################################################
20
+ ##
21
+ ## Gradle start up script for UN*X
22
+ ##
23
+ ##############################################################################
24
+
25
+ # Attempt to set APP_HOME
26
+ # Resolve links: $0 may be a link
27
+ PRG="$0"
28
+ # Need this for relative symlinks.
29
+ while [ -h "$PRG" ] ; do
30
+ ls=`ls -ld "$PRG"`
31
+ link=`expr "$ls" : '.*-> \(.*\)$'`
32
+ if expr "$link" : '/.*' > /dev/null; then
33
+ PRG="$link"
34
+ else
35
+ PRG=`dirname "$PRG"`"/$link"
36
+ fi
37
+ done
38
+ SAVED="`pwd`"
39
+ cd "`dirname \"$PRG\"`/" >/dev/null
40
+ APP_HOME="`pwd -P`"
41
+ cd "$SAVED" >/dev/null
42
+
43
+ APP_NAME="Gradle"
44
+ APP_BASE_NAME=`basename "$0"`
45
+
46
+ # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47
+ DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48
+
49
+ # Use the maximum available, or set MAX_FD != -1 to use that value.
50
+ MAX_FD="maximum"
51
+
52
+ warn () {
53
+ echo "$*"
54
+ }
55
+
56
+ die () {
57
+ echo
58
+ echo "$*"
59
+ echo
60
+ exit 1
61
+ }
62
+
63
+ # OS specific support (must be 'true' or 'false').
64
+ cygwin=false
65
+ msys=false
66
+ darwin=false
67
+ nonstop=false
68
+ case "`uname`" in
69
+ CYGWIN* )
70
+ cygwin=true
71
+ ;;
72
+ Darwin* )
73
+ darwin=true
74
+ ;;
75
+ MINGW* )
76
+ msys=true
77
+ ;;
78
+ NONSTOP* )
79
+ nonstop=true
80
+ ;;
81
+ esac
82
+
83
+ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84
+
85
+
86
+ # Determine the Java command to use to start the JVM.
87
+ if [ -n "$JAVA_HOME" ] ; then
88
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
89
+ # IBM's JDK on AIX uses strange locations for the executables
90
+ JAVACMD="$JAVA_HOME/jre/sh/java"
91
+ else
92
+ JAVACMD="$JAVA_HOME/bin/java"
93
+ fi
94
+ if [ ! -x "$JAVACMD" ] ; then
95
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
96
+
97
+ Please set the JAVA_HOME variable in your environment to match the
98
+ location of your Java installation."
99
+ fi
100
+ else
101
+ JAVACMD="java"
102
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
103
+
104
+ Please set the JAVA_HOME variable in your environment to match the
105
+ location of your Java installation."
106
+ fi
107
+
108
+ # Increase the maximum file descriptors if we can.
109
+ if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
110
+ MAX_FD_LIMIT=`ulimit -H -n`
111
+ if [ $? -eq 0 ] ; then
112
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
113
+ MAX_FD="$MAX_FD_LIMIT"
114
+ fi
115
+ ulimit -n $MAX_FD
116
+ if [ $? -ne 0 ] ; then
117
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
118
+ fi
119
+ else
120
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
121
+ fi
122
+ fi
123
+
124
+ # For Darwin, add options to specify how the application appears in the dock
125
+ if $darwin; then
126
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
127
+ fi
128
+
129
+ # For Cygwin or MSYS, switch paths to Windows format before running java
130
+ if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
131
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
132
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133
+
134
+ JAVACMD=`cygpath --unix "$JAVACMD"`
135
+
136
+ # We build the pattern for arguments to be converted via cygpath
137
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
138
+ SEP=""
139
+ for dir in $ROOTDIRSRAW ; do
140
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
141
+ SEP="|"
142
+ done
143
+ OURCYGPATTERN="(^($ROOTDIRS))"
144
+ # Add a user-defined pattern to the cygpath arguments
145
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
146
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
147
+ fi
148
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
149
+ i=0
150
+ for arg in "$@" ; do
151
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
152
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
153
+
154
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
155
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
156
+ else
157
+ eval `echo args$i`="\"$arg\""
158
+ fi
159
+ i=`expr $i + 1`
160
+ done
161
+ case $i in
162
+ 0) set -- ;;
163
+ 1) set -- "$args0" ;;
164
+ 2) set -- "$args0" "$args1" ;;
165
+ 3) set -- "$args0" "$args1" "$args2" ;;
166
+ 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
167
+ 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
168
+ 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
169
+ 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
170
+ 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
171
+ 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
172
+ esac
173
+ fi
174
+
175
+ # Escape application args
176
+ save () {
177
+ for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
178
+ echo " "
179
+ }
180
+ APP_ARGS=`save "$@"`
181
+
182
+ # Collect all arguments for the java command, following the shell quoting and substitution rules
183
+ eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
184
+
185
+ exec "$JAVACMD" "$@"
@@ -0,0 +1,89 @@
1
+ @rem
2
+ @rem Copyright 2015 the original author or authors.
3
+ @rem
4
+ @rem Licensed under the Apache License, Version 2.0 (the "License");
5
+ @rem you may not use this file except in compliance with the License.
6
+ @rem You may obtain a copy of the License at
7
+ @rem
8
+ @rem https://www.apache.org/licenses/LICENSE-2.0
9
+ @rem
10
+ @rem Unless required by applicable law or agreed to in writing, software
11
+ @rem distributed under the License is distributed on an "AS IS" BASIS,
12
+ @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ @rem See the License for the specific language governing permissions and
14
+ @rem limitations under the License.
15
+ @rem
16
+
17
+ @if "%DEBUG%" == "" @echo off
18
+ @rem ##########################################################################
19
+ @rem
20
+ @rem Gradle startup script for Windows
21
+ @rem
22
+ @rem ##########################################################################
23
+
24
+ @rem Set local scope for the variables with windows NT shell
25
+ if "%OS%"=="Windows_NT" setlocal
26
+
27
+ set DIRNAME=%~dp0
28
+ if "%DIRNAME%" == "" set DIRNAME=.
29
+ set APP_BASE_NAME=%~n0
30
+ set APP_HOME=%DIRNAME%
31
+
32
+ @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33
+ for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34
+
35
+ @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36
+ set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37
+
38
+ @rem Find java.exe
39
+ if defined JAVA_HOME goto findJavaFromJavaHome
40
+
41
+ set JAVA_EXE=java.exe
42
+ %JAVA_EXE% -version >NUL 2>&1
43
+ if "%ERRORLEVEL%" == "0" goto execute
44
+
45
+ echo.
46
+ echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47
+ echo.
48
+ echo Please set the JAVA_HOME variable in your environment to match the
49
+ echo location of your Java installation.
50
+
51
+ goto fail
52
+
53
+ :findJavaFromJavaHome
54
+ set JAVA_HOME=%JAVA_HOME:"=%
55
+ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56
+
57
+ if exist "%JAVA_EXE%" goto execute
58
+
59
+ echo.
60
+ echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61
+ echo.
62
+ echo Please set the JAVA_HOME variable in your environment to match the
63
+ echo location of your Java installation.
64
+
65
+ goto fail
66
+
67
+ :execute
68
+ @rem Setup the command line
69
+
70
+ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71
+
72
+
73
+ @rem Execute Gradle
74
+ "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75
+
76
+ :end
77
+ @rem End local scope for the variables with windows NT shell
78
+ if "%ERRORLEVEL%"=="0" goto mainEnd
79
+
80
+ :fail
81
+ rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82
+ rem the _cmd.exe /c_ return code!
83
+ if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84
+ exit /b 1
85
+
86
+ :mainEnd
87
+ if "%OS%"=="Windows_NT" endlocal
88
+
89
+ :omega
@@ -0,0 +1,4 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
+ package="com.socure.docv.reactnative">
3
+
4
+ </manifest>
@@ -0,0 +1,130 @@
1
+ package com.socure.docv.reactnative
2
+
3
+ import android.app.Activity
4
+ import android.content.Intent
5
+ import android.util.Base64
6
+ import com.facebook.react.bridge.*
7
+ import com.socure.docv.capturesdk.api.Platform.REACT_NATIVE
8
+ import com.socure.docv.capturesdk.api.SocureDocVHelper.getIntent
9
+ import com.socure.docv.capturesdk.api.SocureDocVHelper.getResult
10
+ import com.socure.docv.capturesdk.api.SocureDocVHelper.setSource
11
+ import com.socure.docv.capturesdk.common.utils.ResultListener
12
+ import com.socure.docv.capturesdk.common.utils.ScanError
13
+ import com.socure.docv.capturesdk.common.utils.ScannedData
14
+ import org.json.JSONException
15
+ import org.json.JSONObject
16
+
17
+ class SocureDocVReactNativeModule(reactContext: ReactApplicationContext) :
18
+ ReactContextBaseJavaModule(reactContext), ActivityEventListener {
19
+
20
+ private var onSuccessCallback: Callback? = null
21
+ private var onErrorCallback: Callback? = null
22
+
23
+ init {
24
+ reactApplicationContext.addActivityEventListener(this)
25
+ }
26
+
27
+ override fun getName(): String {
28
+ return "SocureDocVReactNative"
29
+ }
30
+
31
+ @ReactMethod
32
+ fun launchSocureDocV(
33
+ socureApiKey: String,
34
+ flow: String?,
35
+ onSuccess: Callback,
36
+ onError: Callback
37
+ ) {
38
+ this.onSuccessCallback = onSuccess
39
+ this.onErrorCallback = onError
40
+ setSource(REACT_NATIVE)
41
+ currentActivity?.startActivityForResult(
42
+ getIntent(currentActivity!!, socureApiKey, flow),
43
+ 123
44
+ )
45
+ }
46
+
47
+ override fun onActivityResult(
48
+ activity: Activity?,
49
+ requestCode: Int,
50
+ resultCode: Int,
51
+ data: Intent?
52
+ ) {
53
+ data?.let {
54
+ getResult(data, object : ResultListener {
55
+ override fun onSuccess(scannedData: ScannedData) {
56
+ onSuccessCallback?.invoke(convertResultToReadbleMap(scannedData))
57
+ }
58
+
59
+ override fun onError(scanError: ScanError) {
60
+ onErrorCallback?.invoke(convertErrorToReadableMap(scanError))
61
+ }
62
+ })
63
+ }
64
+ }
65
+
66
+ override fun onNewIntent(intent: Intent?) {}
67
+
68
+ private fun convertResultToReadbleMap(scannedData: ScannedData): ReadableMap {
69
+ val docVResponse: WritableMap = Arguments.createMap()
70
+ docVResponse.putString("docUUID", scannedData.docUUID)
71
+ docVResponse.putString("sessionId", scannedData.sessionId)
72
+
73
+ val captureData: WritableMap = Arguments.createMap()
74
+ scannedData.captureData?.forEach {
75
+ captureData.putString(it.key, it.value)
76
+ }
77
+ docVResponse.putMap("captureData", captureData)
78
+
79
+ val capturedImages: WritableMap = Arguments.createMap()
80
+ scannedData.capturedImages?.forEach {
81
+ capturedImages.putString(it.key, Base64.encodeToString(it.value, Base64.DEFAULT) ?: "")
82
+ }
83
+ docVResponse.putMap("capturedImages", capturedImages)
84
+
85
+ scannedData.extractedData?.let { jsonString ->
86
+ try {
87
+ docVResponse.putMap("extractedData", convertStringToMap(JSONObject(jsonString)))
88
+ } catch (ex: JSONException) {
89
+ docVResponse.putString("extractedData", jsonString)
90
+ }
91
+ }
92
+
93
+ return docVResponse
94
+ }
95
+
96
+ private fun convertErrorToReadableMap(scanError: ScanError): ReadableMap {
97
+ val docVErrResponse: WritableMap = Arguments.createMap()
98
+ docVErrResponse.putString("statusCode", scanError.statusCode.toString())
99
+ docVErrResponse.putString("errorMessage", scanError.errorMessage)
100
+ scanError.sessionId?.let {
101
+ docVErrResponse.putString("sessionId", it)
102
+ }
103
+
104
+ val capturedImages: WritableMap = Arguments.createMap()
105
+ scanError.capturedImages?.forEach {
106
+ capturedImages.putString(it.key, Base64.encodeToString(it.value, Base64.DEFAULT) ?: "")
107
+ }
108
+ docVErrResponse.putMap("capturedImages", capturedImages)
109
+
110
+ return docVErrResponse
111
+ }
112
+
113
+ private fun convertStringToMap(jsonObject: JSONObject): ReadableMap {
114
+ val responseMap: WritableMap = Arguments.createMap()
115
+ val jsonIterator = jsonObject.keys()
116
+ while (jsonIterator.hasNext()) {
117
+ val key: String = jsonIterator.next()
118
+ when (val value = jsonObject[key]) {
119
+ is JSONObject -> {
120
+ responseMap.putMap(key, convertStringToMap(value))
121
+ }
122
+ is String -> {
123
+ responseMap.putString(key, value)
124
+ }
125
+ }
126
+ }
127
+ return responseMap
128
+ }
129
+
130
+ }
@@ -0,0 +1,17 @@
1
+ package com.socure.docv.reactnative
2
+
3
+ import com.facebook.react.ReactPackage
4
+ import com.facebook.react.bridge.NativeModule
5
+ import com.facebook.react.bridge.ReactApplicationContext
6
+ import com.facebook.react.uimanager.ViewManager
7
+
8
+
9
+ class SocureDocVReactNativePackage : ReactPackage {
10
+ override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
11
+ return listOf(SocureDocVReactNativeModule(reactContext))
12
+ }
13
+
14
+ override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
15
+ return emptyList()
16
+ }
17
+ }
@@ -0,0 +1,5 @@
1
+ #import <React/RCTBridgeModule.h>
2
+ #import <React/RCTViewManager.h>
3
+ #import <React/RCTBridge.h>
4
+ #import <React/RCTEventDispatcher.h>
5
+ #import <React/RCTUtils.h>
@@ -0,0 +1,14 @@
1
+ #import <React/RCTBridgeModule.h>
2
+
3
+ @interface RCT_EXTERN_MODULE(SocureDocVReactNative, NSObject)
4
+
5
+ RCT_EXTERN_METHOD(launchSocureDocV:(NSString)socureApiKey flow:(NSString)flow
6
+ onSuccess:(RCTResponseSenderBlock)success
7
+ onError:(RCTResponseSenderBlock)error)
8
+
9
+ + (BOOL)requiresMainQueueSetup
10
+ {
11
+ return NO;
12
+ }
13
+
14
+ @end
@@ -0,0 +1,48 @@
1
+ import SocureDocV
2
+
3
+ @objc(SocureDocVReactNative)
4
+ class SocureDocVReactNative: NSObject {
5
+ let objDocVHelper = SocureDocVHelper()
6
+ @objc(launchSocureDocV:flow:onSuccess:onError:)
7
+ func launchSocureDocV(socureApiKey: String, flow: String?, onSuccess: @escaping RCTResponseSenderBlock,onError: @escaping RCTResponseSenderBlock) -> Void {
8
+ var flowConfig: [String: Any]?
9
+ do {
10
+ flowConfig = try flow?.convertToDictionary()
11
+ } catch {
12
+ let errorDict = ["errorMessage": "Invalid config data", "statusCode": "7109"]
13
+ onError([errorDict])
14
+ return
15
+ }
16
+ objDocVHelper.setSource(.reactNative)
17
+ DispatchQueue.main.async {
18
+ let root = RCTPresentedViewController()
19
+ self.objDocVHelper.launch(socureApiKey, presentingViewController: root!, config: flowConfig, completionBlock: { result in
20
+ switch result {
21
+ case .success(let scan):
22
+ onSuccess([scan.dictionary])
23
+ break
24
+ case .failure(let error):
25
+ onError([error.dictionary])
26
+ break
27
+ }
28
+ })
29
+ }
30
+ }
31
+
32
+ @objc static func requiresMainQueueSetup() -> Bool {
33
+ return false
34
+ }
35
+ }
36
+
37
+ extension String {
38
+ func convertToDictionary() throws -> [String: Any]? {
39
+ if let data = self.data(using: .utf8) {
40
+ do {
41
+ return try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any]
42
+ } catch {
43
+ throw error
44
+ }
45
+ }
46
+ return nil
47
+ }
48
+ }
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@socure-inc/docv-react-native",
3
+ "version": "3.0.0",
4
+ "description": "The Predictive Document Verification (DocV) SDK React Native bridge allows you to use the DocV SDK v3 for Android and iOS in your React Native application.",
5
+ "main": "lib/commonjs/index",
6
+ "module": "lib/module/index",
7
+ "types": "lib/typescript/index.d.ts",
8
+ "react-native": "src/index",
9
+ "source": "src/index",
10
+ "keywords": [
11
+ "react-native",
12
+ "ios",
13
+ "android",
14
+ "socure",
15
+ "socure-docv",
16
+ "document-verification"
17
+ ],
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "https://github.com/socure-inc/socure-docv-demo-app-react-native.git"
21
+ },
22
+ "author": "Socure <support@socure.com>",
23
+ "license": "SEE LICENSE IN License.txt",
24
+ "homepage": "https://github.com/socure-inc/socure-docv-demo-app-react-native",
25
+ "publishConfig": {
26
+ "registry": "https://registry.npmjs.org/"
27
+ },
28
+ "peerDependencies": {
29
+ "react": ">=16.13.1",
30
+ "react-native": ">=0.66.0"
31
+ },
32
+ "devDependencies": {
33
+ "react": "17.0.2",
34
+ "react-native": "0.68.2"
35
+ },
36
+ "scripts": {
37
+ "test": "echo \"Error: no test specified\" && exit 1"
38
+ }
39
+ }
@@ -0,0 +1,23 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+ folly_version = '2021.06.28.00-v2'
5
+ folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
6
+
7
+ Pod::Spec.new do |s|
8
+ s.name = "socure-docv-react-native"
9
+ s.version = package["version"]
10
+ s.summary = package["description"]
11
+ s.homepage = package["homepage"]
12
+ s.license = package["license"]
13
+ s.authors = package["author"]
14
+ s.source = { :git => "https://github.com/socure-inc/socure-docv-demo-app-react-native", :tag => "#{s.version}" }
15
+
16
+ s.platforms = { :ios => "13.0" }
17
+
18
+ s.source_files = "ios/**/*.{h,m,mm,swift}"
19
+
20
+ s.dependency "React"
21
+ s.dependency "SocureDocV", "3.0.2"
22
+
23
+ end
package/src/index.tsx ADDED
@@ -0,0 +1,69 @@
1
+ import { NativeModules } from 'react-native';
2
+
3
+ const LINKING_ERROR =
4
+ `The package '@socure-inc/docv-react-native' doesn't seem to be linked.\n\n` +
5
+ '- Rebuilt the app after installing the package';
6
+
7
+ const SocureDocVReactNative = NativeModules.SocureDocVReactNative ? NativeModules.SocureDocVReactNative : new Proxy(
8
+ {},
9
+ {
10
+ get() {
11
+ throw new Error(LINKING_ERROR);
12
+ },
13
+ }
14
+ );
15
+
16
+ export function launchSocureDocV(socureApiKey: string, flow: string | null | undefined, onSuccess: Function, onError: Function) {
17
+ if (typeof socureApiKey !== 'string') {
18
+ onConfigError("7011", "Invalid key", onError)
19
+ } else if (flow && typeof flow !== 'string') {
20
+ onConfigError("7109", "Invalid config data", onError)
21
+ } else {
22
+ return SocureDocVReactNative.launchSocureDocV(socureApiKey, flow, onSuccess, onError);
23
+ }
24
+ }
25
+
26
+ function onConfigError(errorCode: string, errorMessage: string, onError?: Function) {
27
+ let error = { statusCode: errorCode, errorMessage: errorMessage } as ScanError
28
+ if (onError && typeof onError == 'function') {
29
+ onError(error)
30
+ } else {
31
+ throw Promise.reject(error)
32
+ }
33
+ }
34
+
35
+ export interface ScannedData {
36
+ docUUID: string
37
+ sessionId: string
38
+ extractedData?: ExtractedInfo
39
+ captureData: { [doc_type: string]: [capture_type: string] }
40
+ capturedImages: { [doc_type: string]: [image_data: string] }
41
+ }
42
+
43
+ export interface ScanError {
44
+ statusCode: string
45
+ errorMessage: string
46
+ sessionId?: string
47
+ capturedImages?: { [doc_type: string]: [image_data: string] }
48
+ }
49
+
50
+ export interface ExtractedInfo {
51
+ type?: string
52
+ expirationDate?: string
53
+ dob?: string
54
+ firstName?: string
55
+ fullName?: string
56
+ documentNumber?: string
57
+ address?: string
58
+ surName?: string
59
+ issueDate?: string
60
+ parsedAddress?: AddressInfo
61
+ }
62
+
63
+ export interface AddressInfo {
64
+ state?: String
65
+ postalCode?: String
66
+ city?: String
67
+ country?: String
68
+ physicalAddress?: String
69
+ }