react-native-shield-fraud-plugin 1.0.7 → 1.0.9
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.
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
package com.shieldfraudplugin;
|
|
2
2
|
|
|
3
3
|
import android.app.Activity;
|
|
4
|
+
import android.os.Handler;
|
|
5
|
+
import android.os.Looper;
|
|
4
6
|
|
|
5
7
|
import androidx.annotation.NonNull;
|
|
6
8
|
|
|
@@ -30,161 +32,163 @@ import javax.annotation.Nullable;
|
|
|
30
32
|
|
|
31
33
|
@ReactModule(name = ShieldFraudPluginModule.NAME)
|
|
32
34
|
public class ShieldFraudPluginModule extends ReactContextBaseJavaModule implements ShieldCallback<JSONObject> {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
48
|
-
public boolean isShieldInitialized() {
|
|
49
|
-
try {
|
|
50
|
-
return Shield.getInstance() != null;
|
|
51
|
-
} catch (IllegalStateException e) {
|
|
52
|
-
return false;
|
|
35
|
+
public static final String NAME = "ShieldFraudPlugin";
|
|
36
|
+
private final ReactApplicationContext reactContext;
|
|
37
|
+
|
|
38
|
+
public ShieldFraudPluginModule(ReactApplicationContext reactContext) {
|
|
39
|
+
super(reactContext);
|
|
40
|
+
this.reactContext = reactContext;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@Override
|
|
44
|
+
@NonNull
|
|
45
|
+
public String getName() {
|
|
46
|
+
return NAME;
|
|
53
47
|
}
|
|
54
|
-
}
|
|
55
48
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
49
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
50
|
+
public boolean isShieldInitialized() {
|
|
51
|
+
try {
|
|
52
|
+
return Shield.getInstance() != null;
|
|
53
|
+
} catch (IllegalStateException e) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
60
56
|
}
|
|
61
|
-
Activity currentActivity = getCurrentActivity();
|
|
62
|
-
if (currentActivity != null) {
|
|
63
|
-
Shield.Builder builder = new Shield.Builder(currentActivity, siteID, secretKey)
|
|
64
|
-
.setAutoBlockDialog(getBlockedDialogFromReadableMap(blockedDialog));
|
|
65
57
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
58
|
+
@ReactMethod
|
|
59
|
+
public void initShield(String siteID, String secretKey, Boolean isOptimizedListener, ReadableMap blockedDialog, Integer logLevel, Integer environment) {
|
|
60
|
+
if (isShieldInitialized()) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
Activity currentActivity = getCurrentActivity();
|
|
64
|
+
if (currentActivity != null) {
|
|
65
|
+
Shield.Builder builder = new Shield.Builder(currentActivity, siteID, secretKey)
|
|
66
|
+
.setAutoBlockDialog(getBlockedDialogFromReadableMap(blockedDialog));
|
|
67
|
+
|
|
68
|
+
if (isOptimizedListener) {
|
|
69
|
+
builder.registerDeviceShieldCallback(this);
|
|
70
|
+
}
|
|
69
71
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
+
String environmentString = getEnvironmentStringFromInteger(environment);
|
|
73
|
+
builder.setEnvironment(environmentString);
|
|
72
74
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
+
Shield.LogLevel logLevelEnum = getLogLevelEnumFromInteger(logLevel);
|
|
76
|
+
builder.setLogLevel(logLevelEnum);
|
|
75
77
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
+
Shield shield = builder.build();
|
|
79
|
+
Shield.setSingletonInstance(shield);
|
|
80
|
+
}
|
|
78
81
|
}
|
|
79
|
-
}
|
|
80
82
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
83
|
+
private BlockedDialog getBlockedDialogFromReadableMap(ReadableMap blockedDialog) {
|
|
84
|
+
if (blockedDialog != null) {
|
|
85
|
+
String title = blockedDialog.hasKey("title") ? blockedDialog.getString("title") : null;
|
|
86
|
+
String body = blockedDialog.hasKey("body") ? blockedDialog.getString("body") : null;
|
|
87
|
+
return new BlockedDialog(title, body);
|
|
88
|
+
}
|
|
89
|
+
return null;
|
|
86
90
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
91
|
+
|
|
92
|
+
private String getEnvironmentStringFromInteger(Integer environment) {
|
|
93
|
+
String environmentString;
|
|
94
|
+
switch (environment) {
|
|
95
|
+
case 1:
|
|
96
|
+
environmentString = Shield.ENVIRONMENT_DEV;
|
|
97
|
+
break;
|
|
98
|
+
case 2:
|
|
99
|
+
environmentString = Shield.ENVIRONMENT_STAGING;
|
|
100
|
+
break;
|
|
101
|
+
default:
|
|
102
|
+
environmentString = Shield.ENVIRONMENT_PROD;
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
return environmentString;
|
|
102
106
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
107
|
+
|
|
108
|
+
private Shield.LogLevel getLogLevelEnumFromInteger(Integer logLevel) {
|
|
109
|
+
Shield.LogLevel logLevelEnum;
|
|
110
|
+
switch (logLevel) {
|
|
111
|
+
case 1:
|
|
112
|
+
logLevelEnum = Shield.LogLevel.NONE;
|
|
113
|
+
break;
|
|
114
|
+
case 2:
|
|
115
|
+
logLevelEnum = Shield.LogLevel.INFO;
|
|
116
|
+
break;
|
|
117
|
+
case 3:
|
|
118
|
+
logLevelEnum = Shield.LogLevel.DEBUG;
|
|
119
|
+
break;
|
|
120
|
+
default:
|
|
121
|
+
logLevelEnum = Shield.LogLevel.VERBOSE;
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
return logLevelEnum;
|
|
121
125
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
144
|
-
public String getSessionId() {
|
|
145
|
-
return Shield.getInstance().getSessionId();
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
@Override
|
|
149
|
-
public void onSuccess(@Nullable JSONObject jsonObject) {
|
|
150
|
-
if (jsonObject != null) {
|
|
151
|
-
reactContext
|
|
152
|
-
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
153
|
-
.emit("success", jsonObject.toString());
|
|
126
|
+
|
|
127
|
+
@ReactMethod
|
|
128
|
+
public void setDeviceResultStateListener() {
|
|
129
|
+
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
|
|
130
|
+
@Override
|
|
131
|
+
public void run() {
|
|
132
|
+
Shield.getInstance().setDeviceResultStateListener(new Shield.DeviceResultStateListener() {
|
|
133
|
+
@Override
|
|
134
|
+
public void isReady() {
|
|
135
|
+
// Emit an event when the device is ready
|
|
136
|
+
WritableMap params = Arguments.createMap();
|
|
137
|
+
params.putString("status", "isSDKReady");
|
|
138
|
+
reactContext
|
|
139
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
140
|
+
.emit("device_result_state", params);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}, 1500);
|
|
154
145
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
reactContext
|
|
161
|
-
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
162
|
-
.emit("error", e.getLocalizedMessage());
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
149
|
+
public String getSessionId() {
|
|
150
|
+
return Shield.getInstance().getSessionId();
|
|
163
151
|
}
|
|
164
152
|
|
|
165
|
-
|
|
153
|
+
@Override
|
|
154
|
+
public void onSuccess(@Nullable JSONObject jsonObject) {
|
|
155
|
+
if (jsonObject != null) {
|
|
156
|
+
reactContext
|
|
157
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
158
|
+
.emit("success", jsonObject.toString());
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
@Override
|
|
163
|
+
public void onFailure(@Nullable ShieldException e) {
|
|
164
|
+
if (e != null) {
|
|
165
|
+
reactContext
|
|
166
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
167
|
+
.emit("error", e.getLocalizedMessage());
|
|
168
|
+
}
|
|
166
169
|
|
|
167
|
-
@ReactMethod
|
|
168
|
-
public void sendAttributes(String screenName, ReadableMap json) {
|
|
169
|
-
HashMap<String,String> data =new HashMap<String,String>();
|
|
170
|
-
for (Map.Entry<String, Object> entry : json.toHashMap().entrySet()) {
|
|
171
|
-
data.put(entry.getKey(), (String) entry.getValue());
|
|
172
170
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
171
|
+
|
|
172
|
+
@ReactMethod
|
|
173
|
+
public void sendAttributes(String screenName, ReadableMap json) {
|
|
174
|
+
HashMap<String, String> data = new HashMap<String, String>();
|
|
175
|
+
for (Map.Entry<String, Object> entry : json.toHashMap().entrySet()) {
|
|
176
|
+
data.put(entry.getKey(), (String) entry.getValue());
|
|
177
|
+
}
|
|
178
|
+
Shield.getInstance().sendAttributes(screenName, data);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
@ReactMethod
|
|
182
|
+
public void getLatestDeviceResult(Callback successCallback, Callback errorCallback) {
|
|
183
|
+
Shield shieldInstance = Shield.getInstance();
|
|
184
|
+
JSONObject deviceResult = shieldInstance.getLatestDeviceResult();
|
|
185
|
+
|
|
186
|
+
if (deviceResult != null) {
|
|
187
|
+
successCallback.invoke(deviceResult.toString());
|
|
181
188
|
} else {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
errorMessage = error.getMessage();
|
|
186
|
-
}
|
|
187
|
-
errorCallback.invoke(errorMessage);
|
|
189
|
+
ShieldException error = shieldInstance.getResponseError();
|
|
190
|
+
String errorMessage = (error != null) ? error.getMessage() : "unknown error";
|
|
191
|
+
errorCallback.invoke(errorMessage);
|
|
188
192
|
}
|
|
189
|
-
|
|
193
|
+
}
|
|
190
194
|
}
|
package/ios/ShieldFraudPlugin.m
CHANGED
|
@@ -54,11 +54,18 @@ RCT_EXPORT_METHOD(getLatestDeviceResult:(RCTResponseSenderBlock)successCallback
|
|
|
54
54
|
|
|
55
55
|
RCT_EXPORT_METHOD(setDeviceResultStateListener)
|
|
56
56
|
{
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
double delayInSeconds = 1.5;
|
|
58
|
+
|
|
59
|
+
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
|
|
60
|
+
|
|
61
|
+
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
|
|
62
|
+
[[Shield shared] setDeviceResultStateListener:^{
|
|
63
|
+
[self sendEventWithName:@"device_result_state" body:@{@"status": @"isSDKReady"}];
|
|
64
|
+
}];
|
|
65
|
+
});
|
|
60
66
|
}
|
|
61
67
|
|
|
68
|
+
|
|
62
69
|
- (NSArray<NSString *> *)supportedEvents {
|
|
63
70
|
return @[@"success", @"error", @"device_result_state"];
|
|
64
71
|
}
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-shield-fraud-plugin",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "React Native Shield Fraud 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.",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|