react-native-shield-full-plugin 2.3.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.
Files changed (30) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +237 -0
  3. package/android/build.gradle +109 -0
  4. package/android/gradle.properties +5 -0
  5. package/android/src/main/AndroidManifest.xml +5 -0
  6. package/android/src/main/java/com/shieldfraudplugin/ShieldFraudPluginModule.java +441 -0
  7. package/android/src/main/java/com/shieldfraudplugin/ShieldFraudPluginPackage.java +78 -0
  8. package/android/src/newarch/java/com/shieldfraudplugin/ShieldFraudPluginSpec.java +41 -0
  9. package/android/src/oldarch/java/com/shieldfraudplugin/ShieldFraudPluginSpec.java +36 -0
  10. package/ios/ShieldFraudPlugin.h +24 -0
  11. package/ios/ShieldFraudPlugin.mm +295 -0
  12. package/ios/ShieldFraudPlugin.xcodeproj/project.pbxproj +282 -0
  13. package/ios/ShieldFraudPlugin.xcodeproj/project.xcworkspace/contents.xcworkspacedata +4 -0
  14. package/lib/commonjs/NativeShieldFraudPlugin.js +15 -0
  15. package/lib/commonjs/NativeShieldFraudPlugin.js.map +1 -0
  16. package/lib/commonjs/index.js +256 -0
  17. package/lib/commonjs/index.js.map +1 -0
  18. package/lib/module/NativeShieldFraudPlugin.js +10 -0
  19. package/lib/module/NativeShieldFraudPlugin.js.map +1 -0
  20. package/lib/module/index.js +253 -0
  21. package/lib/module/index.js.map +1 -0
  22. package/lib/typescript/src/NativeShieldFraudPlugin.d.ts +53 -0
  23. package/lib/typescript/src/NativeShieldFraudPlugin.d.ts.map +1 -0
  24. package/lib/typescript/src/index.d.ts +143 -0
  25. package/lib/typescript/src/index.d.ts.map +1 -0
  26. package/package.json +169 -0
  27. package/react-native-shield-fraud-plugin.podspec +29 -0
  28. package/react-native-shield-full-plugin.podspec +29 -0
  29. package/src/NativeShieldFraudPlugin.ts +87 -0
  30. package/src/index.tsx +334 -0
package/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 shield.com
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,237 @@
1
+ # React Native Shield Full Plugin
2
+
3
+ React Native Plugin for Shield Full (www.shield.com)
4
+
5
+ React Native Shield Full Plugin helps developers to assess malicious activities performed on mobile devices and return risk intelligence based on user's behaviour. It collects device's fingerprint, social metrics and network information.
6
+
7
+ There are few steps to getting started with the SHIELD SDK:
8
+
9
+ 1. [Integrate the SDK](#integrate-the-sdk)
10
+
11
+ 2. [Initialize the SDK](#initialize-the-sdk)
12
+
13
+ 3. [Get Session ID](#get-session-id)
14
+
15
+ 4. [Get Device Results](#get-device-results)
16
+
17
+ 5. [Send Custom Attributes](#send-custom-attributes)
18
+
19
+ 6. [Send Device Fingerprint](#send-device-signature)
20
+
21
+ 7. [Migration from BRIDGE CODE to PLUGIN](#migration-from-bridge-code-to-plugin)
22
+
23
+
24
+
25
+ ### Integrate the SDK
26
+
27
+ This package can be installed in two ways, you can choose a way depends on your need.
28
+
29
+ **NPM:**
30
+ ```
31
+ npm install react-native-shield-full-plugin
32
+ ```
33
+ **OR**
34
+
35
+ **YARN:**
36
+ ```
37
+ yarn add react-native-shield-full-plugin
38
+ ```
39
+
40
+ **Note**: We make continuous enhancements to our full library and detection capabilities which includes new functionalities, bug fixes and security updates. We recommend updating to the latest SDK version to protect against rapidly evolving fraud risks.
41
+
42
+ You can refer to the Changelog to see more details about our updates.
43
+
44
+ ### Initialize the SDK
45
+
46
+ The SDK initialization should be configured on `useEffect` *(for **Functional Components**)* or `componentDidMount` *(for **Class Components**)* in your **App.tsx** or on **App launch** to ensure successful generation and processing of the device fingerprint. The SDK is to be initialized only once and will throw an exception if it is initialized more than once.
47
+
48
+ You need both the **SHIELD_SITE_ID** and **SHIELD_SECRET_KEY** to initialize the SDK. You can locate them at the top of the page.
49
+ ```
50
+ const config: Config = {
51
+ siteID: 'SHIELD_SITE_ID',
52
+ secretKey: 'SHIELD_SECRET_KEY'
53
+ };
54
+
55
+ useEffect(() => {
56
+ const initializeShield = async () => {
57
+ await ShieldFraud.initShield(config);
58
+ };
59
+
60
+ initializeShield();
61
+ }, []);
62
+ ```
63
+ **Note** - ```await ShieldFraud.initShield(config)``` - *The await keyword is used to wait for the promise returned by the initShield function to resolve. In React Native, It is best practice to use `await` when calling native modules from React Native, especially during `asynchronous` operations such as SDK Initialization. This is because using `await` ensures that the main thread is not blocked while the native module is initializing.*
64
+
65
+ `Config` has these **optional** parameters:
66
+
67
+ 1. `logLevel` Set your log level to `debug`, `info` or `none`. | Receives high-level information about how the SDK processes network requests, responses or error information during SDK integration. Default log level is `none`.
68
+ 2. `environmentInfo` Set your environment info to `prod`, `dev` or `staging`. Default environment info is `prod`.
69
+ 3. `blockedDialog` Set your dialog for the blocked dialog both title and body or you can send it as null as well
70
+
71
+ Note: You can check whether Shield SDK is ready or not by using isSDKready function
72
+
73
+ ```
74
+ ShieldFraud.isSDKready(async (isReady: boolean) => {
75
+ if (isReady) {
76
+ // Shield is Ready: Do your implementation
77
+ }
78
+ }
79
+ ```
80
+
81
+ ### Get Session ID
82
+ Session ID is the unique identifier of a user’s app session and acts as a point of reference when retrieving the device result for that session.
83
+
84
+
85
+ Session ID follows the OS lifecycle management, in-line with industry best practice. This means that a user’s session is active for as long as the device maintains it, unless the user terminates the app or the device runs out of memory and has to kill the app.
86
+
87
+ If you would like to retrieve device results using the backend API, it is important that you store the Session ID on your system. You will need to call the SHIELD backend API using this Session ID.
88
+
89
+ ```
90
+ ShieldFraud.isSDKready(async (isReady: boolean) => {
91
+ if (isReady) {
92
+ const sessionID = await ShieldFraud.getSessionId(); // Fetch session ID using await
93
+ console.log('session id: ', sessionID);
94
+ }
95
+ }
96
+ ```
97
+
98
+ ### Get Device Results
99
+ SHIELD provides you actionable device intelligence which you can retrieve from the SDK, via the `Optimized Listener` or `Customized Pull method`. You can also retrieve results via the backend API.
100
+
101
+ *Warning: Only 1 method of obtaining device results **(Optimized Listener or Customized Pull)** can be in effect at any point in time.*
102
+
103
+ #### Retrieve device results via Optimized Listener
104
+
105
+ ##### SHIELD recommends the Optimized Listener method to reduce number of API calls. #####
106
+
107
+ Our SDK will capture an initial device fingerprint upon SDK initialization and return an additional set of device intelligence ONLY if the device fingerprint changes along one session. This ensures a truly optimized end to end protection of your ecosystem.
108
+
109
+ You can register a callback if you would like to be notified in the event that the device attributes change during the session (for example, a user activates a malicious tool a moment after launching the page).
110
+
111
+ Add an additional parameter during intialization in order to register a callback.
112
+
113
+ **For example - `await ShieldFraud.initShield(config, callbacks);`**
114
+ ```
115
+ const callbacks: ShieldCallback = {
116
+ onSuccess: (data) => {
117
+ // Handle success event here
118
+ console.log('Success:', data);
119
+ },
120
+ onFailure: (error) => {
121
+ // Handle failure event here
122
+ console.log('Error:', error);
123
+ },
124
+ };
125
+
126
+ const config: Config = {
127
+ siteID: 'SHIELD_SITE_ID',
128
+ secretKey: 'SHIELD_SECRET_KEY'
129
+ };
130
+
131
+ useEffect(() => {
132
+ const initializeShield = async () => {
133
+ await ShieldFraud.initShield(config, callbacks);
134
+ };
135
+ initializeShield();
136
+ }, []);
137
+ ```
138
+
139
+ #### Retrieve device results via Customized Pull
140
+ You can retrieve device results via Customized Pull at specific user checkpoints or activities, such as account registration, login, or checkout. This is to ensure that there is adequate time to generate a device fingerprint.
141
+
142
+ ```
143
+ ShieldFraud.isSDKready(async (isReady: boolean) => {
144
+ if (isReady) {
145
+ ShieldFraud.getLatestDeviceResult()
146
+ .then((result: object) => {
147
+ // Handle success with the result object
148
+ console.log('Received latest device result:', result);
149
+ })
150
+ .catch((error: object) => {
151
+ // Handle error with the error object
152
+ console.log('Error retrieving device result:', error);
153
+ });
154
+ }
155
+ });
156
+ ```
157
+
158
+ It is possible that getLatestDeviceResult returns null if the device result retrieval is unsuccessful.
159
+
160
+ ### Send Custom Attributes
161
+
162
+ Use the sendAttributes function to sent event-based attributes such as user_id or activity_id for enhanced analytics. This function accepts two parameters:screenName where the function is triggered, and data to provide any custom fields in key, value pairs.
163
+
164
+ ```
165
+ ShieldFraud.isSDKready(async (isReady: boolean) => {
166
+ if (isReady) {
167
+ ShieldFraud.sendAttributes('Screen_Name', { key1: 'value1', key2: 'value2' });
168
+ }
169
+ }
170
+ ```
171
+
172
+ ### Send Device Fingerprint
173
+
174
+ Use the sendDeviceSignature function to manually trigger device signature collection for a screen or user checkpoint.
175
+
176
+ ```
177
+ // with screen name only
178
+ const deviceintelligence = await ShieldFraud.sendDeviceSignature('screen_name');
179
+
180
+ // with screen name and user id
181
+ const deviceintelligence = await ShieldFraud.sendDeviceSignature('screen_name', 'user_id');
182
+
183
+ ```
184
+
185
+ ### Migration from BRIDGE CODE to PLUGIN
186
+ If you've been using the old method of integrating the React Native bridge code for the Shield Full SDK on iOS and Android, follow these steps to migrate to our plugin.
187
+
188
+ #### iOS Migration Steps
189
+
190
+ **1. Remove Old Pod Dependency:**
191
+ Open your iOS project's Podfile and remove the line `pod 'ShieldFraud'`. Then, in your project's root directory, run `pod deintegrate` followed by `pod install` to ensure the old ShieldFraud dependency is completely removed.
192
+
193
+ **2. Remove Old Bridge Code Files:**
194
+ In your Xcode project's file explorer, locate and remove the files `ShieldModule.h` and `ShieldModule.m`. Remove all these references as they are no longer needed.
195
+
196
+ **3. Clean the Project:**
197
+ Open your Xcode project. Go to `"Product"` in the top menu and select `"Clean Build Folder"` to make sure any residual build artifacts related to the old ShieldFraud library are removed.
198
+
199
+ **4. Update React Native Project:**
200
+ In your React Native project, search for any code that references the old `ShieldModule`. Remove all these references as they are no longer needed.
201
+
202
+ **5. Follow Plugin Integration Steps:**
203
+ Now that you've cleaned up the old bridge code, follow the integration steps outlined in the documentation under "Integrate the SDK" section, starting from the step of installing the plugin using npm or yarn.
204
+
205
+ #### Android Migration Steps
206
+ If you've been using the old method of integrating the React Native bridge code for the Shield Full SDK on Android, follow these steps to migrate to our plugin.
207
+
208
+ **1. Remove Old Dependencies:**
209
+ In your `app/build.gradle` file, locate and remove the line:
210
+ ```
211
+ implementation 'com.shield.android:shield-fraud:1.5.+'
212
+ ```
213
+
214
+ **2. Update Android Settings:**
215
+ In your `settings.gradle` or project level `build.gradle` file from the `repositories` block, locate and remove the `maven url`:
216
+ ```
217
+ allprojects {
218
+ repositories {
219
+ maven {
220
+ url "https://cashshield-sdk.s3.amazonaws.com/release/"
221
+ }
222
+ ...
223
+ }
224
+ }
225
+ ```
226
+ This is the maven url that you no longer need with the new plugin approach.
227
+
228
+ **3. Remove Old Bridge Code:**
229
+ In your Android project, if you have a ShieldModule.java file as part of the old bridge code integration, you can safely remove it.
230
+
231
+ **4. Update React Native Project:**
232
+ In your React Native project, search for any code that references the old ShieldModule in Java code. Also remove ShieldModule from ReactPackage, Remove all these references as they are no longer needed.
233
+
234
+ **5. Follow Plugin Integration Steps:**
235
+ Now that you've cleaned up the old bridge code, follow the integration steps outlined in the documentation under "Integrate the SDK" section, starting from the step of installing the plugin using npm or yarn.
236
+
237
+ By following these steps, you'll successfully migrate your React Native project from the old bridge code integration to the new Shield Full plugin. This migration will make your project more maintainable and allow you to take advantage of the new features and improvements offered by the plugin.
@@ -0,0 +1,109 @@
1
+ buildscript {
2
+ repositories {
3
+ google()
4
+ mavenCentral()
5
+ }
6
+
7
+ dependencies {
8
+ classpath "com.android.tools.build:gradle:4.1.3"
9
+ }
10
+ }
11
+
12
+ def isNewArchitectureEnabled() {
13
+ return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
14
+ }
15
+
16
+ // Detect which npm package is installed by reading its own package.json.
17
+ // When published as react-native-shield-full-plugin the name field differs.
18
+ def packageJson = new groovy.json.JsonSlurper().parseText(
19
+ new File("${project.projectDir}/../package.json").text
20
+ )
21
+ def isFullPlugin = packageJson.name == "react-native-shield-full-plugin"
22
+ def shieldSdkArtifact = isFullPlugin ? "com.shield.android:shield:2.6.1" : "com.shield.android:shield-fraud:2.6.1"
23
+
24
+ apply plugin: "com.android.library"
25
+
26
+ if (isNewArchitectureEnabled()) {
27
+ apply plugin: "com.facebook.react"
28
+ }
29
+
30
+ def getExtOrDefault(name) {
31
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["ShieldFraudPlugin_" + name]
32
+ }
33
+
34
+ def getExtOrIntegerDefault(name) {
35
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["ShieldFraudPlugin_" + name]).toInteger()
36
+ }
37
+
38
+ android {
39
+ compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
40
+
41
+ // Conditional for compatibility with AGP <4.2.
42
+ if (project.android.hasProperty("namespace")) {
43
+ namespace 'com.shieldfraudplugin'
44
+ }
45
+
46
+ defaultConfig {
47
+ minSdkVersion getExtOrIntegerDefault("minSdkVersion")
48
+ targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
49
+ buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
50
+ }
51
+
52
+ buildTypes {
53
+ release {
54
+ minifyEnabled false
55
+ }
56
+ }
57
+
58
+ lintOptions {
59
+ disable "GradleCompatible"
60
+ }
61
+
62
+ compileOptions {
63
+ sourceCompatibility JavaVersion.VERSION_1_8
64
+ targetCompatibility JavaVersion.VERSION_1_8
65
+ }
66
+
67
+ sourceSets {
68
+ main {
69
+ // Select the architecture-specific ShieldFraudPluginSpec shim at build time.
70
+ // - oldarch: extends ReactContextBaseJavaModule (Old Architecture / bridge)
71
+ // - newarch: extends the codegen-generated NativeShieldFraudPluginSpec (New Architecture)
72
+ if (isNewArchitectureEnabled()) {
73
+ java.srcDirs += ['src/newarch']
74
+ } else {
75
+ java.srcDirs += ['src/oldarch']
76
+ }
77
+ }
78
+ }
79
+
80
+ if (isNewArchitectureEnabled()) {
81
+ react {
82
+ jsRootDir = file("../src/")
83
+ libraryName = "ShieldFraudPlugin"
84
+ codegenJavaPackageName = "com.shieldfraudplugin"
85
+ }
86
+ }
87
+ }
88
+
89
+ rootProject.allprojects {
90
+ repositories {
91
+ mavenCentral()
92
+ google()
93
+ maven {
94
+ url "https://cashshield-sdk.s3.amazonaws.com/release/"
95
+ content {
96
+ includeGroup "com.shield.android"
97
+ includeGroup "com.shield.android.module"
98
+ }
99
+ }
100
+ }
101
+ }
102
+
103
+ dependencies {
104
+ // For < 0.71, this will be from the local maven repo
105
+ // For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
106
+ implementation "com.facebook.react:react-native:0.71.7"
107
+
108
+ implementation shieldSdkArtifact
109
+ }
@@ -0,0 +1,5 @@
1
+ ShieldFraudPlugin_kotlinVersion=1.7.0
2
+ ShieldFraudPlugin_minSdkVersion=21
3
+ ShieldFraudPlugin_targetSdkVersion=31
4
+ ShieldFraudPlugin_compileSdkVersion=31
5
+ ShieldFraudPlugin_ndkversion=21.4.7075529
@@ -0,0 +1,5 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
+ package="com.shieldfraudplugin">
3
+
4
+ <uses-permission android:name="android.permission.INTERNET" />
5
+ </manifest>