@regulaforensics/idv 3.2.23-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/README.md +36 -0
  2. package/RNIDV.podspec +21 -0
  3. package/android/CVDIDV.kt +48 -0
  4. package/android/build.gradle +41 -0
  5. package/android/cordova.gradle +20 -0
  6. package/android/src/main/java/com/regula/plugin/idv/JSONConstructor.kt +135 -0
  7. package/android/src/main/java/com/regula/plugin/idv/Main.kt +124 -0
  8. package/android/src/main/java/com/regula/plugin/idv/RNIDVModule.kt +71 -0
  9. package/android/src/main/java/com/regula/plugin/idv/Utils.kt +60 -0
  10. package/examples/capacitor/README.md +15 -0
  11. package/examples/capacitor/android/app/build.gradle +50 -0
  12. package/examples/capacitor/android/app/capacitor.build.gradle +22 -0
  13. package/examples/capacitor/android/app/proguard-rules.pro +21 -0
  14. package/examples/capacitor/android/app/src/main/AndroidManifest.xml +26 -0
  15. package/examples/capacitor/android/app/src/main/assets/Regula/.gitkeep +0 -0
  16. package/examples/capacitor/android/app/src/main/java/com/regula/example/idv/capacitor/MainActivity.java +5 -0
  17. package/examples/capacitor/android/app/src/main/res/drawable/ic_launcher.png +0 -0
  18. package/examples/capacitor/android/app/src/main/res/drawable/ic_launcher_foreground.png +0 -0
  19. package/examples/capacitor/android/app/src/main/res/drawable/ic_launcher_round.png +0 -0
  20. package/examples/capacitor/android/app/src/main/res/drawable/launcher.xml +4 -0
  21. package/examples/capacitor/android/app/src/main/res/drawable/launcher_round.xml +4 -0
  22. package/examples/capacitor/android/app/src/main/res/drawable/splash.png +0 -0
  23. package/examples/capacitor/android/app/src/main/res/layout/activity_main.xml +12 -0
  24. package/examples/capacitor/android/app/src/main/res/values/styles.xml +22 -0
  25. package/examples/capacitor/android/build.gradle +30 -0
  26. package/examples/capacitor/android/capacitor.settings.gradle +15 -0
  27. package/examples/capacitor/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  28. package/examples/capacitor/android/gradle/wrapper/gradle-wrapper.properties +7 -0
  29. package/examples/capacitor/android/gradle.properties +22 -0
  30. package/examples/capacitor/android/gradlew +252 -0
  31. package/examples/capacitor/android/gradlew.bat +94 -0
  32. package/examples/capacitor/android/settings.gradle +5 -0
  33. package/examples/capacitor/android/variables.gradle +16 -0
  34. package/examples/capacitor/index.html +5 -0
  35. package/examples/capacitor/index.tsx +16 -0
  36. package/examples/capacitor/ionic.config.json +7 -0
  37. package/examples/capacitor/ios/App/App/App.entitlements +10 -0
  38. package/examples/capacitor/ios/App/App/AppDelegate.swift +49 -0
  39. package/examples/capacitor/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-512@2x.png +0 -0
  40. package/examples/capacitor/ios/App/App/Assets.xcassets/AppIcon.appiconset/Contents.json +14 -0
  41. package/examples/capacitor/ios/App/App/Assets.xcassets/Contents.json +6 -0
  42. package/examples/capacitor/ios/App/App/Assets.xcassets/Splash.imageset/Contents.json +23 -0
  43. package/examples/capacitor/ios/App/App/Assets.xcassets/Splash.imageset/splash-2732x2732-1.png +0 -0
  44. package/examples/capacitor/ios/App/App/Assets.xcassets/Splash.imageset/splash-2732x2732-2.png +0 -0
  45. package/examples/capacitor/ios/App/App/Assets.xcassets/Splash.imageset/splash-2732x2732.png +0 -0
  46. package/examples/capacitor/ios/App/App/Base.lproj/LaunchScreen.storyboard +32 -0
  47. package/examples/capacitor/ios/App/App/Base.lproj/Main.storyboard +19 -0
  48. package/examples/capacitor/ios/App/App/Info.plist +65 -0
  49. package/examples/capacitor/ios/App/App.xcodeproj/project.pbxproj +414 -0
  50. package/examples/capacitor/ios/App/App.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  51. package/examples/capacitor/ios/App/App.xcworkspace/contents.xcworkspacedata +10 -0
  52. package/examples/capacitor/ios/App/App.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  53. package/examples/capacitor/ios/App/Podfile +26 -0
  54. package/examples/capacitor/package.json +27 -0
  55. package/examples/capacitor/public/assets/.gitkeep +0 -0
  56. package/examples/capacitor/scripts/android.sh +9 -0
  57. package/examples/capacitor/scripts/ios.sh +8 -0
  58. package/examples/capacitor/scripts/setup.sh +14 -0
  59. package/examples/capacitor/src/main.css +148 -0
  60. package/examples/capacitor/src/main.html +38 -0
  61. package/examples/capacitor/src/main.tsx +10 -0
  62. package/examples/capacitor/tsconfig.json +5 -0
  63. package/examples/capacitor/vite.config.ts +17 -0
  64. package/examples/ionic/README.md +15 -0
  65. package/examples/ionic/angular.json +39 -0
  66. package/examples/ionic/assets/.gitkeep +0 -0
  67. package/examples/ionic/config.xml +59 -0
  68. package/examples/ionic/images/icon.png +0 -0
  69. package/examples/ionic/index.html +19 -0
  70. package/examples/ionic/index.tsx +28 -0
  71. package/examples/ionic/ionic.config.json +7 -0
  72. package/examples/ionic/package.json +46 -0
  73. package/examples/ionic/scripts/android.sh +8 -0
  74. package/examples/ionic/scripts/ios.sh +8 -0
  75. package/examples/ionic/scripts/setup.sh +8 -0
  76. package/examples/ionic/src/main.css +148 -0
  77. package/examples/ionic/src/main.html +38 -0
  78. package/examples/ionic/src/main.tsx +10 -0
  79. package/examples/ionic/tsconfig.json +14 -0
  80. package/examples/react_native/README.md +15 -0
  81. package/examples/react_native/app.config.ts +46 -0
  82. package/examples/react_native/assets/.gitkeep +0 -0
  83. package/examples/react_native/images/icon.png +0 -0
  84. package/examples/react_native/index.html +11 -0
  85. package/examples/react_native/index.tsx +63 -0
  86. package/examples/react_native/metro.config.js +7 -0
  87. package/examples/react_native/package.json +29 -0
  88. package/examples/react_native/scripts/android.sh +13 -0
  89. package/examples/react_native/scripts/ios.sh +12 -0
  90. package/examples/react_native/scripts/setup.sh +9 -0
  91. package/examples/react_native/src/main.css +148 -0
  92. package/examples/react_native/src/main.html +38 -0
  93. package/examples/react_native/src/main.tsx +10 -0
  94. package/ios/CVDIDV.swift +72 -0
  95. package/ios/FlutterIDVPlugin.swift +72 -0
  96. package/ios/JSONConstructor.swift +134 -0
  97. package/ios/Main.swift +89 -0
  98. package/ios/RNIDV.swift +72 -0
  99. package/ios/Utils.swift +56 -0
  100. package/package.json +38 -0
  101. package/plugin.xml +45 -0
  102. package/test/json.tsx +0 -0
  103. package/test/package-lock.json +584 -0
  104. package/test/package.json +9 -0
  105. package/test/test.tsx +3 -0
  106. package/test/utils.tsx +38 -0
  107. package/www/capacitor/index.js +6 -0
  108. package/www/capacitor/internal/bridge.js +19 -0
  109. package/www/capacitor/internal/cordova.js +17 -0
  110. package/www/cordova.js +150 -0
  111. package/www/react-native/index.js +6 -0
  112. package/www/react-native/internal/bridge.js +19 -0
  113. package/www/types/index.d.ts +12 -0
package/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Regula IDV plugin
2
+ IDV is a framework that unifies access to all Regula products. This plugin makes possible to use it with react-native, cordova and capacitor applications.
3
+
4
+ ## Android Integration
5
+
6
+
7
+ TODO check this
8
+
9
+
10
+ In order to use this plugin, in `android/app/build.gradle` add `kotlin-kapt` plugin and enable `dataBinding`:
11
+ ```
12
+ plugins {
13
+ id "kotlin-kapt"
14
+ }
15
+
16
+ android {
17
+ buildFeatures {
18
+ dataBinding true
19
+ }
20
+ }
21
+ ```
22
+
23
+ ## Demo applications
24
+ In the [examples](examples/) folder you can find 3 demo applications:
25
+ * [React-native](examples/react-native)
26
+ * [Ionic(ionic app with cordova, angular)](examples/ionic)
27
+ * [Capacitor(ionic app with capacitor, react)](examples/capacitor)
28
+
29
+ Each demo app has its own readme file with instructions on building and installation.
30
+
31
+ ## Documentation
32
+ * [Documentation](https://docs.regulaforensics.com/develop/idv-sdk/mobile)
33
+ * [API Reference](https://dev.regulaforensics.com/npm-idv)
34
+
35
+ ## Support
36
+ If you have any technical questions, feel free to [contact](mailto:support@regulaforensics.com) us or create issues [here](https://github.com/regulaforensics/npm-idv/issues).
package/RNIDV.podspec ADDED
@@ -0,0 +1,21 @@
1
+ require 'json'
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
4
+ source = File.join(__dir__, 'ios')
5
+
6
+ Pod::Spec.new do |s|
7
+ s.name = 'RNIDV'
8
+ s.version = '3.2.23-beta'
9
+ s.summary = package['description']
10
+ s.license = package['license']
11
+
12
+ s.authors = { 'RegulaForensics' => 'support@regulaforensics.com' }
13
+ s.homepage = 'https://regulaforensics.com'
14
+
15
+ s.source = { http: "file:#{source}" }
16
+ s.ios.deployment_target = '14.0'
17
+ s.source_files = 'ios/**/*.{h,m}'
18
+ s.exclude_files = [ 'ios/CVDIDV.swift' ]
19
+ s.dependency 'IDVSDK', '3.1.1492'
20
+ s.dependency 'React'
21
+ end
@@ -0,0 +1,48 @@
1
+ package com.regula.plugin.idv
2
+
3
+ import android.content.Context
4
+ import android.util.Log
5
+ import org.apache.cordova.CallbackContext
6
+ import org.apache.cordova.CordovaPlugin
7
+ import org.apache.cordova.PluginResult
8
+ import org.json.JSONArray
9
+
10
+ val eventCallbackIds = mutableMapOf<String, String>()
11
+
12
+ lateinit var args: JSONArray
13
+ lateinit var binding: CordovaPlugin
14
+ val context: Context
15
+ get() = binding.cordova.context
16
+
17
+ fun sendEvent(callbackId: String, data: Any? = "") {
18
+ val pluginResult = when (data) {
19
+ is Int -> PluginResult(PluginResult.Status.OK, data)
20
+ is Boolean -> PluginResult(PluginResult.Status.OK, data)
21
+ else -> PluginResult(PluginResult.Status.OK, data.toSendable() as String?)
22
+ }
23
+ pluginResult.keepCallback = true
24
+ binding.webView.sendPluginResult(pluginResult, eventCallbackIds[callbackId] ?: callbackId)
25
+ }
26
+
27
+ @Suppress("UNCHECKED_CAST")
28
+ fun <T> argsNullable(index: Int): T? = if (args.get(index).toString() != "null") {
29
+ args.get(index) as T
30
+ } else null
31
+
32
+ class CVDIDV : CordovaPlugin() {
33
+ init {
34
+ binding = this
35
+ }
36
+
37
+ override fun execute(action: String, arguments: JSONArray, callbackContext: CallbackContext): Boolean {
38
+ args = arguments
39
+ val method = args.remove(0) as String
40
+ if (method == "setEvent") eventCallbackIds[args(0)] = callbackContext.callbackId
41
+ try {
42
+ methodCall(method) { data: Any? -> sendEvent(callbackContext.callbackId, data) }
43
+ } catch (error: Exception) {
44
+ Log.e("REGULA", "Caught exception in \"$method\" function:", error)
45
+ }
46
+ return true
47
+ }
48
+ }
@@ -0,0 +1,41 @@
1
+ apply plugin: 'com.android.library'
2
+ apply plugin: 'kotlin-android'
3
+ apply plugin: 'kotlin-kapt'
4
+
5
+ android {
6
+ // Conditional for compatibility with AGP <4.2.
7
+ if (project.android.hasProperty("namespace")) {
8
+ namespace 'com.regula.plugin.idv'
9
+ }
10
+
11
+ compileSdk 36
12
+
13
+ defaultConfig {
14
+ minSdkVersion 24
15
+ targetSdk 36
16
+ versionCode 1
17
+ versionName "1.0"
18
+ }
19
+
20
+ buildFeatures {
21
+ dataBinding true
22
+ }
23
+ }
24
+
25
+ rootProject.allprojects {
26
+ repositories {
27
+ maven {
28
+ url "https://maven.regulaforensics.com/RegulaDocumentReader"
29
+ }
30
+ }
31
+ }
32
+
33
+ dependencies {
34
+ //noinspection GradleDynamicVersion
35
+ implementation 'com.facebook.react:react-native:+'
36
+ //noinspection GradleDependency
37
+ implementation('com.regula.idv:api:3.1.90') {
38
+ transitive = true
39
+ }
40
+ }
41
+
@@ -0,0 +1,20 @@
1
+ apply plugin: 'kotlin-kapt'
2
+
3
+ android {
4
+ buildFeatures {
5
+ dataBinding true
6
+ }
7
+ }
8
+
9
+ repositories {
10
+ maven {
11
+ url "https://maven.regulaforensics.com/RegulaDocumentReader"
12
+ }
13
+ }
14
+
15
+ dependencies {
16
+ //noinspection GradleDependency
17
+ implementation('com.regula.idv:api:3.1.90') {
18
+ transitive = true
19
+ }
20
+ }
@@ -0,0 +1,135 @@
1
+ @file:Suppress("unused")
2
+
3
+ package com.regula.plugin.idv
4
+
5
+ import com.regula.idv.api.config.ApiKeyConnectionConfig
6
+ import com.regula.idv.api.config.CredentialsConnectionConfig
7
+ import com.regula.idv.api.config.PrepareWorkflowConfig
8
+ import com.regula.idv.api.config.StartWorkflowConfig
9
+ import com.regula.idv.api.config.TokenConnectionConfig
10
+ import com.regula.idv.api.models.WorkflowResult
11
+ import com.regula.idv.api.models.Workflow
12
+ import com.regula.idv.api.models.WorkflowStep
13
+ import com.regula.idv.module.BaseException
14
+ import org.json.JSONObject
15
+
16
+ fun generateCompletion(success: Any?, error: BaseException?) = mapOf(
17
+ "success" to success,
18
+ "error" to error?.message
19
+ ).toJson()
20
+
21
+ // Config ------------------------------
22
+
23
+ fun credentialsConnectionConfigFromJSON(it: JSONObject) = CredentialsConnectionConfig(
24
+ it.getString("baseUrl"),
25
+ it.getString("userName"),
26
+ it.getString("password")
27
+ ).let { self ->
28
+ self.httpTimeoutMs = it.getIntOrNull("httpTimeoutMs")
29
+ return@let self
30
+ }
31
+
32
+ fun generateCredentialsConnectionConfig(it: CredentialsConnectionConfig) = mapOf(
33
+ "baseUrl" to it.baseUrl,
34
+ "userName" to it.userName,
35
+ "password" to it.password,
36
+ "httpTimeoutMs" to it.httpTimeoutMs,
37
+ ).toJson()
38
+
39
+ fun tokenConnectionConfigFromJSON(it: JSONObject) = TokenConnectionConfig(
40
+ it.getString("url")
41
+ )
42
+
43
+ fun generateTokenConnectionConfig(it: TokenConnectionConfig) = mapOf(
44
+ "url" to it.baseUrl,
45
+ ).toJson()
46
+
47
+ fun apiKeyConnectionConfigFromJSON(it: JSONObject) = ApiKeyConnectionConfig(
48
+ it.getString("baseUrl"),
49
+ it.getString("apiKey"),
50
+ it.getIntOrNull("ttl"),
51
+ ).let { self ->
52
+ self.httpTimeoutMs = it.getIntOrNull("httpTimeoutMs")
53
+ return@let self
54
+ }
55
+
56
+ fun generateApiKeyConnectionConfig(it: ApiKeyConnectionConfig) = mapOf(
57
+ "baseUrl" to it.baseUrl,
58
+ "apiKey" to it.apiKey,
59
+ "ttl" to it.ttl,
60
+ "httpTimeoutMs" to it.httpTimeoutMs,
61
+ ).toJson()
62
+
63
+ fun prepareWorkflowConfigFromJSON(it: JSONObject) = PrepareWorkflowConfig(
64
+ it.getString("workflowId"),
65
+ )
66
+
67
+ fun generatePrepareWorkflowConfig(it: PrepareWorkflowConfig) = mapOf(
68
+ "workflowId" to it.workflowId,
69
+ ).toJson()
70
+
71
+ fun startWorkflowConfigFromJSON(input: JSONObject?) = input?.let { json ->
72
+ val builder = StartWorkflowConfig.Builder()
73
+
74
+ json.getStringOrNull("locale")?.let { builder.setLocale(it) }
75
+ json.getJSONObjectOrNull("metadata")?.let { builder.setMetadata(it) }
76
+
77
+ builder.build()
78
+ }
79
+
80
+ fun generateStartWorkflowConfig(input: StartWorkflowConfig?) = input?.let {
81
+ mapOf(
82
+ "locale" to it.locale,
83
+ "metadata" to it.metadata,
84
+ ).toJson()
85
+ }
86
+
87
+ // Model ------------------------------
88
+
89
+ fun workflowFromJSON(input: JSONObject?) = input?.let {
90
+ Workflow(
91
+ it.getString("id"),
92
+ it.getString("name"),
93
+ it.getString("version"),
94
+ it.getString("description"),
95
+ it.getStringOrNull("defaultLocale"),
96
+ )
97
+ }
98
+
99
+ fun generateWorkflow(input: Workflow?) = input?.let {
100
+ mapOf(
101
+ "id" to it.id,
102
+ "name" to it.name,
103
+ "version" to it.version,
104
+ "description" to it.description,
105
+ "defaultLocale" to it.defaultLocale,
106
+ ).toJson()
107
+ }
108
+
109
+ fun workflowStepFromJSON(input: JSONObject?) = input?.let {
110
+ WorkflowStep(
111
+ it.getString("id"),
112
+ it.getString("name"),
113
+ )
114
+ }
115
+
116
+ fun generateWorkflowStep(input: WorkflowStep?) = input?.let {
117
+ mapOf(
118
+ "id" to it.id,
119
+ "name" to it.name,
120
+ ).toJson()
121
+ }
122
+
123
+ fun workflowResultFromJSON(input: JSONObject?): WorkflowResult? = input?.let {
124
+ WorkflowResult(
125
+ it.getString("sessionId"),
126
+ workflowStepFromJSON(it.getJSONObjectOrNull("finalStep"))!!
127
+ )
128
+ }
129
+
130
+ fun generateWorkflowResult(input: WorkflowResult?) = input?.let {
131
+ mapOf(
132
+ "sessionId" to it.sessionId,
133
+ "finalStep" to generateWorkflowStep(it.finalStep),
134
+ ).toJson()
135
+ }
@@ -0,0 +1,124 @@
1
+ package com.regula.plugin.idv
2
+
3
+ import com.regula.idv.api.IdvSdk.Companion.instance
4
+ import com.regula.idv.api.config.InitConfig
5
+ import com.regula.idv.api.enums.SessionRestoreMode
6
+ import com.regula.idv.api.listeners.IdvSdkListener
7
+ import com.regula.idv.module.BaseException
8
+ import com.regula.idv.module.IModule
9
+ import org.json.JSONObject
10
+
11
+ const val didStartSessionEvent = "didStartSessionEvent"
12
+ const val didEndSessionEvent = "didEndSessionEvent"
13
+ const val didStartRestoreSessionEvent = "didStartRestoreSessionEvent"
14
+ const val didContinueRemoteSessionEvent = "didContinueRemoteSessionEvent"
15
+
16
+ val allModules = listOf(
17
+ "com.regula.idv.docreader.DocReaderModule",
18
+ "com.regula.idv.face.FaceModule",
19
+ )
20
+
21
+ fun methodCall(method: String, callback: Callback): Any = when (method) {
22
+ "setSessionRestoreMode" -> instance().sessionRestoreMode = SessionRestoreMode.entries[args(0)]
23
+ "getCurrentSessionId" -> callback(instance().currentSessionId())
24
+ "initialize" -> initialize(callback)
25
+ "deinitialize" -> deinitialize(callback)
26
+ "configureWithToken" -> configureWithToken(callback, args(0))
27
+ "configureWithCredentials" -> configureWithCredentials(callback, args(0))
28
+ "configureWithApiKey" -> configureWithApiKey(callback, args(0))
29
+ "prepareWorkflow" -> prepareWorkflow(callback, args(0))
30
+ "startWorkflow" -> startWorkflow(callback, argsNullable(0))
31
+ "getWorkflows" -> getWorkflows(callback)
32
+ else -> Unit
33
+ }
34
+
35
+ fun initialize(callback: Callback) {
36
+ val includedModules = mutableListOf<IModule>()
37
+ for (className in allModules) try {
38
+ includedModules.add(Class.forName(className).getDeclaredConstructor().newInstance() as IModule)
39
+ } catch (_: Exception) {
40
+ }
41
+
42
+ instance().initialize(context, InitConfig(includedModules)) {
43
+ instance().listener = listener
44
+ generateCompletion(
45
+ it.isSuccess,
46
+ it.exceptionOrNull() as BaseException?
47
+ ).send(callback)
48
+ }
49
+ }
50
+
51
+ fun deinitialize(callback: Callback) {
52
+ instance().deinitialize(context) {
53
+ generateCompletion(
54
+ it.isSuccess,
55
+ it.exceptionOrNull() as BaseException?
56
+ ).send(callback)
57
+ }
58
+ }
59
+
60
+
61
+ fun configureWithToken(callback: Callback, data: JSONObject) = instance().configure(
62
+ context,
63
+ tokenConnectionConfigFromJSON(data)
64
+ ) {
65
+ generateCompletion(
66
+ it.getOrNull(),
67
+ it.exceptionOrNull() as BaseException?
68
+ ).send(callback)
69
+ }
70
+
71
+ fun configureWithCredentials(callback: Callback, data: JSONObject) = instance().configure(
72
+ context,
73
+ credentialsConnectionConfigFromJSON(data)
74
+ ) {
75
+ generateCompletion(
76
+ it.isSuccess,
77
+ it.exceptionOrNull() as BaseException?
78
+ ).send(callback)
79
+ }
80
+
81
+ fun configureWithApiKey(callback: Callback, data: JSONObject) = instance().configure(
82
+ context,
83
+ apiKeyConnectionConfigFromJSON(data)
84
+ ) {
85
+ generateCompletion(
86
+ it.isSuccess,
87
+ it.exceptionOrNull() as BaseException?
88
+ ).send(callback)
89
+ }
90
+
91
+ fun prepareWorkflow(callback: Callback, data: JSONObject) = instance().prepareWorkflow(
92
+ context,
93
+ prepareWorkflowConfigFromJSON(data)
94
+ ) {
95
+ generateCompletion(
96
+ generateWorkflow(it.getOrNull()),
97
+ it.exceptionOrNull() as BaseException?
98
+ ).send(callback)
99
+ }
100
+
101
+ fun startWorkflow(callback: Callback, data: JSONObject?) = instance().startWorkflow(
102
+ context,
103
+ startWorkflowConfigFromJSON(data)
104
+ ) {
105
+ generateCompletion(
106
+ generateWorkflowResult(it.getOrNull()),
107
+ it.exceptionOrNull() as BaseException?
108
+ ).send(callback)
109
+ }
110
+
111
+ fun getWorkflows(callback: Callback) = instance().getWorkflows {
112
+ generateCompletion(
113
+ it.getOrNull().toJsonNullable(::generateWorkflow),
114
+ it.exceptionOrNull() as BaseException?
115
+ ).send(callback)
116
+ }
117
+
118
+ // Weak references
119
+ var listener = object : IdvSdkListener {
120
+ override fun didStartSession() = sendEvent(didStartSessionEvent)
121
+ override fun didEndSession() = sendEvent(didEndSessionEvent)
122
+ override fun didStartRestoreSession() = sendEvent(didStartRestoreSessionEvent)
123
+ override fun didContinueRemoteSession() = sendEvent(didContinueRemoteSessionEvent)
124
+ }
@@ -0,0 +1,71 @@
1
+ @file:Suppress("unused", "UNUSED_PARAMETER")
2
+
3
+ package com.regula.plugin.idv
4
+
5
+ import android.content.Context
6
+ import android.util.Log
7
+ import com.facebook.react.ReactPackage
8
+ import com.facebook.react.bridge.Promise
9
+ import com.facebook.react.bridge.ReactApplicationContext
10
+ import com.facebook.react.bridge.ReactContext
11
+ import com.facebook.react.bridge.ReactContextBaseJavaModule
12
+ import com.facebook.react.bridge.ReactMethod
13
+ import com.facebook.react.bridge.ReadableArray
14
+ import com.facebook.react.modules.core.DeviceEventManagerModule
15
+ import com.facebook.react.uimanager.ViewManager
16
+ import org.json.JSONArray
17
+ import org.json.JSONObject
18
+
19
+ var listenerCount = 0
20
+
21
+ lateinit var args: JSONArray
22
+ lateinit var binding: ReactContext
23
+ val context: Context
24
+ get() = binding.applicationContext
25
+
26
+ fun sendEvent(event: String, data: Any? = "") {
27
+ if (listenerCount <= 0) return
28
+ val result = if (data is JSONObject || data is JSONArray) data.toString() else data.toString() + ""
29
+ binding.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java).emit(event, result)
30
+ }
31
+
32
+ @Suppress("UNCHECKED_CAST")
33
+ fun <T> argsNullable(index: Int): T? {
34
+ val value = args[index]
35
+ if (value is Double && value % 1 == 0.0) return value.toInt() as T
36
+ if (value.toString() == "null") return null
37
+ return value as T
38
+ }
39
+
40
+ class RNIDVPackage : ReactPackage {
41
+ override fun createNativeModules(reactContext: ReactApplicationContext) = listOf(RNIDVModule(reactContext))
42
+ override fun createViewManagers(reactContext: ReactApplicationContext) = emptyList<ViewManager<*, *>>()
43
+ }
44
+
45
+ class RNIDVModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
46
+ init {
47
+ binding = reactContext
48
+ }
49
+
50
+ @ReactMethod
51
+ fun addListener(eventName: String) {
52
+ listenerCount += 1
53
+ }
54
+
55
+ @ReactMethod
56
+ fun removeListeners(count: Int) {
57
+ listenerCount -= count
58
+ }
59
+
60
+ @ReactMethod
61
+ fun exec(method: String, arguments: ReadableArray, promise: Promise) {
62
+ args = JSONArray(arguments.toArrayList())
63
+ try {
64
+ methodCall(method) { data -> promise.resolve(data.toSendable()) }
65
+ } catch (error: Exception) {
66
+ Log.e("REGULA", "Caught exception in \"$method\" function:", error)
67
+ }
68
+ }
69
+
70
+ override fun getName() = "RNIDV"
71
+ }
@@ -0,0 +1,60 @@
1
+ package com.regula.plugin.idv
2
+
3
+ import org.json.JSONArray
4
+ import org.json.JSONObject
5
+
6
+ inline fun <reified T> args(index: Int) = argsNullable<T>(index)!!
7
+ typealias Callback = (Any?) -> Unit
8
+
9
+ fun List<*>.toJson(): JSONArray {
10
+ val result = JSONArray()
11
+ for (i in indices)
12
+ when (val v = this[i]) {
13
+ null -> result.put(null)
14
+ is Map<*, *> -> result.put(v.toJson())
15
+ is List<*> -> result.put(v.toJson())
16
+ else -> result.put(v)
17
+ }
18
+ return result
19
+ }
20
+
21
+ fun Map<*, *>.toJson(): JSONObject {
22
+ val result = JSONObject()
23
+ for ((k, v) in this) {
24
+ when (v) {
25
+ null -> result.put(k as String, null)
26
+ is Map<*, *> -> result.put(k as String, v.toJson())
27
+ is List<*> -> result.put(k as String, v.toJson())
28
+ else -> result.put(k as String, v)
29
+ }
30
+ }
31
+ return result
32
+ }
33
+
34
+ fun Any?.toSendable(): Any? = this?.let {
35
+ if (it is JSONObject || it is JSONArray) it.toString()
36
+ else it
37
+ }
38
+
39
+ fun JSONObject.send(callback: Callback) = callback(this)
40
+
41
+ fun <T> List<T>?.toJsonNullable(toJson: (T?) -> Any?) = this?.let {
42
+ val result = JSONArray()
43
+ for (item in it) result.put(toJson(item))
44
+ result
45
+ }
46
+
47
+ fun JSONObject.getJSONObjectOrNull(name: String): JSONObject? {
48
+ if (has(name) && get(name).toString() != "null") return getJSONObject(name)
49
+ return null
50
+ }
51
+
52
+ fun JSONObject.getStringOrNull(name: String): String? {
53
+ if (has(name) && get(name).toString() != "null") return getString(name)
54
+ return null
55
+ }
56
+
57
+ fun JSONObject.getIntOrNull(name: String): Int? {
58
+ if (has(name) && get(name).toString() != "null") return getInt(name)
59
+ return null
60
+ }
@@ -0,0 +1,15 @@
1
+ # Regula IDV Capacitor demo application
2
+
3
+ ## How to build demo application
4
+ 1. Download or the clone current repository using the command `git clone https://github.com/regulaforensics/npm-idv.git`.
5
+ 2. Put `regula.license` file at `public/assets/` (you can get a trial license [here](https://client.regulaforensics.com)).
6
+ 3. Put `db.dat` file at `public/assets/` (you can get a trial database [here](https://client.regulaforensics.com/customer/databases))
7
+ 4. Execute `npm run setup` within this directory.
8
+ 5. In `src/main.tsx` choose prefered login configuration(`loginType` variable) and provide your login data according to it: username and password for `credentials`, tokenUrl for `token`, apiKey for `apiKey`.
9
+ 6. Run the app:
10
+ * IOS: `npm run ios`.
11
+ * Android: `npm run android`.
12
+ 7. After initialization choose **General KYC - AP** from workflows list and click **Start Workflow** button.
13
+ 8. Complete workflow and get your session id.
14
+
15
+ **Note**: `npm run ios`/`npm run android` is just one way of running the app. You can also pass `-o` or `--open` argument to the command, and this will open Xcode/Android Studio, then run the app directly from the IDE. Overall, this is a more consistent way, so if you're having troubles running the app from terminal, try running it from the IDE.
@@ -0,0 +1,50 @@
1
+ apply plugin: 'com.android.application'
2
+
3
+ android {
4
+ namespace "com.regula.example.idv.capacitor"
5
+ compileSdkVersion rootProject.ext.compileSdkVersion
6
+ defaultConfig {
7
+ applicationId "com.regula.example.idv.capacitor"
8
+ minSdkVersion rootProject.ext.minSdkVersion
9
+ targetSdkVersion rootProject.ext.targetSdkVersion
10
+ versionCode 1
11
+ versionName "1.0"
12
+ aaptOptions {
13
+ // Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.
14
+ // Default: https://android.googlesource.com/platform/frameworks/base/+/282e181b58cf72b6ca770dc7ca5f91f135444502/tools/aapt/AaptAssets.cpp#61
15
+ ignoreAssetsPattern '!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~'
16
+ }
17
+ }
18
+ buildTypes {
19
+ release {
20
+ minifyEnabled false
21
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22
+ }
23
+ }
24
+ }
25
+
26
+ repositories {
27
+ flatDir{
28
+ dirs '../capacitor-cordova-android-plugins/src/main/libs', 'libs'
29
+ }
30
+ }
31
+
32
+ dependencies {
33
+ implementation fileTree(include: ['*.jar'], dir: 'libs')
34
+ implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
35
+ implementation "androidx.coordinatorlayout:coordinatorlayout:$androidxCoordinatorLayoutVersion"
36
+ implementation "androidx.core:core-splashscreen:$coreSplashScreenVersion"
37
+ implementation project(':capacitor-android')
38
+ implementation project(':capacitor-cordova-android-plugins')
39
+ }
40
+
41
+ apply from: 'capacitor.build.gradle'
42
+
43
+ try {
44
+ def servicesJSON = file('google-services.json')
45
+ if (servicesJSON.text) {
46
+ apply plugin: 'com.google.gms.google-services'
47
+ }
48
+ } catch(Exception e) {
49
+ logger.info("google-services.json not found, google-services plugin not applied. Push Notifications won't work")
50
+ }
@@ -0,0 +1,22 @@
1
+ // DO NOT EDIT THIS FILE! IT IS GENERATED EACH TIME "capacitor update" IS RUN
2
+
3
+ android {
4
+ compileOptions {
5
+ sourceCompatibility JavaVersion.VERSION_21
6
+ targetCompatibility JavaVersion.VERSION_21
7
+ }
8
+ }
9
+
10
+ apply from: "../capacitor-cordova-android-plugins/cordova.variables.gradle"
11
+ dependencies {
12
+ implementation project(':capacitor-app')
13
+ implementation project(':capacitor-haptics')
14
+ implementation project(':capacitor-keyboard')
15
+ implementation project(':capacitor-status-bar')
16
+ implementation "androidx.core:core:1.6.+"
17
+ implementation "androidx.webkit:webkit:1.4.0"
18
+ }
19
+
20
+ if (hasProperty('postBuildExtras')) {
21
+ postBuildExtras()
22
+ }
@@ -0,0 +1,21 @@
1
+ # Add project specific ProGuard rules here.
2
+ # You can control the set of applied configuration files using the
3
+ # proguardFiles setting in build.gradle.
4
+ #
5
+ # For more details, see
6
+ # http://developer.android.com/guide/developing/tools/proguard.html
7
+
8
+ # If your project uses WebView with JS, uncomment the following
9
+ # and specify the fully qualified class name to the JavaScript interface
10
+ # class:
11
+ #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12
+ # public *;
13
+ #}
14
+
15
+ # Uncomment this to preserve the line number information for
16
+ # debugging stack traces.
17
+ #-keepattributes SourceFile,LineNumberTable
18
+
19
+ # If you keep the line number information, uncomment this to
20
+ # hide the original source file name.
21
+ #-renamesourcefileattribute SourceFile