react-native-shield-fraud-plugin 1.0.7 → 1.0.8

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,164 @@ import javax.annotation.Nullable;
30
32
 
31
33
  @ReactModule(name = ShieldFraudPluginModule.NAME)
32
34
  public class ShieldFraudPluginModule extends ReactContextBaseJavaModule implements ShieldCallback<JSONObject> {
33
- public static final String NAME = "ShieldFraudPlugin";
34
- private final ReactApplicationContext reactContext;
35
-
36
- public ShieldFraudPluginModule(ReactApplicationContext reactContext) {
37
- super(reactContext);
38
- this.reactContext = reactContext;
39
- }
40
-
41
- @Override
42
- @NonNull
43
- public String getName() {
44
- return NAME;
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
- @ReactMethod
57
- public void initShield(String siteID, String secretKey, Boolean isOptimizedListener, ReadableMap blockedDialog, Integer logLevel, Integer environment) {
58
- if (isShieldInitialized()) {
59
- return;
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
- if (isOptimizedListener) {
67
- builder.registerDeviceShieldCallback(this);
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
- String environmentString = getEnvironmentStringFromInteger(environment);
71
- builder.setEnvironment(environmentString);
72
+ String environmentString = getEnvironmentStringFromInteger(environment);
73
+ builder.setEnvironment(environmentString);
72
74
 
73
- Shield.LogLevel logLevelEnum = getLogLevelEnumFromInteger(logLevel);
74
- builder.setLogLevel(logLevelEnum);
75
+ Shield.LogLevel logLevelEnum = getLogLevelEnumFromInteger(logLevel);
76
+ builder.setLogLevel(logLevelEnum);
75
77
 
76
- Shield shield = builder.build();
77
- Shield.setSingletonInstance(shield);
78
+ Shield shield = builder.build();
79
+ Shield.setSingletonInstance(shield);
80
+ }
78
81
  }
79
- }
80
82
 
81
- private BlockedDialog getBlockedDialogFromReadableMap(ReadableMap blockedDialog) {
82
- if (blockedDialog != null) {
83
- String title = blockedDialog.hasKey("title") ? blockedDialog.getString("title") : null;
84
- String body = blockedDialog.hasKey("body") ? blockedDialog.getString("body") : null;
85
- return new BlockedDialog(title, body);
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
- return null;
88
- }
89
-
90
- private String getEnvironmentStringFromInteger(Integer environment) {
91
- String environmentString;
92
- switch (environment) {
93
- case 1:
94
- environmentString = Shield.ENVIRONMENT_DEV;
95
- break;
96
- case 2:
97
- environmentString = Shield.ENVIRONMENT_STAGING;
98
- break;
99
- default:
100
- environmentString = Shield.ENVIRONMENT_PROD;
101
- break;
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
- return environmentString;
104
- }
105
-
106
- private Shield.LogLevel getLogLevelEnumFromInteger(Integer logLevel) {
107
- Shield.LogLevel logLevelEnum;
108
- switch (logLevel) {
109
- case 1:
110
- logLevelEnum = Shield.LogLevel.NONE;
111
- break;
112
- case 2:
113
- logLevelEnum = Shield.LogLevel.INFO;
114
- break;
115
- case 3:
116
- logLevelEnum = Shield.LogLevel.DEBUG;
117
- break;
118
- default:
119
- logLevelEnum = Shield.LogLevel.VERBOSE;
120
- break;
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
- return logLevelEnum;
123
- }
124
-
125
- @ReactMethod
126
- public void setDeviceResultStateListener() {
127
- Shield.getInstance().setDeviceResultStateListener(new Shield.DeviceResultStateListener() {
128
- @Override
129
- public void isReady() {
130
- // Emit an event when the device is ready
131
- WritableMap params = Arguments.createMap();
132
- params.putString("status", "isSDKReady");
133
-
134
- reactContext
135
- .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
136
- .emit("device_result_state", params);
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
- @Override
158
- public void onFailure(@Nullable ShieldException e) {
159
- if (e != null) {
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
- Shield.getInstance().sendAttributes(screenName, data);
174
- }
175
171
 
176
- @ReactMethod
177
- public void getLatestDeviceResult(Callback successCallback, Callback errorCallback) {
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) {
178
183
  if (Shield.getInstance().getLatestDeviceResult() != null) {
179
- JSONObject deviceResult = Shield.getInstance().getLatestDeviceResult();
180
- successCallback.invoke(deviceResult.toString());
184
+ JSONObject deviceResult = Shield.getInstance().getLatestDeviceResult();
185
+ successCallback.invoke(deviceResult.toString());
181
186
  } else {
182
- ShieldException error = Shield.getInstance().getResponseError();
183
- String errorMessage = "unknown error";
184
- if (error != null) {
185
- errorMessage = error.getMessage();
186
- }
187
- errorCallback.invoke(errorMessage);
187
+ ShieldException error = Shield.getInstance().getResponseError();
188
+ String errorMessage = "unknown error";
189
+ if (error != null) {
190
+ errorMessage = error.getMessage();
191
+ }
192
+ errorCallback.invoke(errorMessage);
188
193
  }
189
- }
194
+ }
190
195
  }
@@ -54,11 +54,18 @@ RCT_EXPORT_METHOD(getLatestDeviceResult:(RCTResponseSenderBlock)successCallback
54
54
 
55
55
  RCT_EXPORT_METHOD(setDeviceResultStateListener)
56
56
  {
57
- [[Shield shared] setDeviceResultStateListener:^{
58
- [self sendEventWithName:@"device_result_state" body:@{@"status": @"isSDKReady"}];
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-shield-fraud-plugin",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
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",