react-native-shield-fraud-plugin 1.0.4 → 1.0.6

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/README.md CHANGED
@@ -4,7 +4,7 @@ React Native Plugin for Shield Fraud (www.shield.com)
4
4
 
5
5
  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.
6
6
 
7
- There are four steps to getting started with the SHIELD SDK:
7
+ There are few steps to getting started with the SHIELD SDK:
8
8
 
9
9
  1. [Integrate the SDK](#integrate-the-sdk)
10
10
 
@@ -16,6 +16,9 @@ There are four steps to getting started with the SHIELD SDK:
16
16
 
17
17
  5. [Send Custom Attributes](#send-custom-attributes)
18
18
 
19
+ 6. [Migration from BRIDGE CODE to PLUGIN](#migration-from-bridge-code-to-plugin)
20
+
21
+
19
22
 
20
23
  ### Integrate the SDK
21
24
 
@@ -158,4 +161,56 @@ ShieldFraud.isSDKready(async (isReady: boolean) => {
158
161
  }
159
162
  ```
160
163
 
164
+ ### Migration from BRIDGE CODE to PLUGIN
165
+ If you've been using the old method of integrating the React Native bridge code for the Shield Fraud SDK on iOS and Android, follow these steps to migrate to our plugin.
166
+
167
+ #### iOS Migration Steps
168
+
169
+ **1. Remove Old Pod Dependency:**
170
+ 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.
171
+
172
+ **2. Remove Old Bridge Code Files:**
173
+ 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.
174
+
175
+ **3. Clean the Project:**
176
+ 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.
177
+
178
+ **4. Update React Native Project:**
179
+ In your React Native project, search for any code that references the old `ShieldModule`. Remove all these references as they are no longer needed.
180
+
181
+ **5. Follow Plugin Integration Steps:**
182
+ 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.
183
+
184
+ #### Android Migration Steps
185
+ If you've been using the old method of integrating the React Native bridge code for the Shield Fraud SDK on Android, follow these steps to migrate to our plugin.
186
+
187
+ **1. Remove Old Dependencies:**
188
+ In your `app/build.gradle` file, locate and remove the line:
189
+ ```
190
+ implementation 'com.shield.android:shield-fraud:1.5.+'
191
+ ```
192
+
193
+ **2. Update Android Settings:**
194
+ In your `settings.gradle` or project level `build.gradle` file from the `repositories` block, locate and remove the `maven url`:
195
+ ```
196
+ allprojects {
197
+ repositories {
198
+ maven {
199
+ url "https://cashshield-sdk.s3.amazonaws.com/release/"
200
+ }
201
+ ...
202
+ }
203
+ }
204
+ ```
205
+ This is the maven url that you no longer need with the new plugin approach.
206
+
207
+ **3. Remove Old Bridge Code:**
208
+ In your Android project, if you have a ShieldModule.java file as part of the old bridge code integration, you can safely remove it.
209
+
210
+ **4. Update React Native Project:**
211
+ 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.
212
+
213
+ **5. Follow Plugin Integration Steps:**
214
+ 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.
161
215
 
216
+ By following these steps, you'll successfully migrate your React Native project from the old bridge code integration to the new Shield Fraud 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.
@@ -4,10 +4,12 @@ import android.app.Activity;
4
4
 
5
5
  import androidx.annotation.NonNull;
6
6
 
7
+ import com.facebook.react.bridge.Arguments;
7
8
  import com.facebook.react.bridge.Promise;
8
9
  import com.facebook.react.bridge.ReactApplicationContext;
9
10
  import com.facebook.react.bridge.ReactContextBaseJavaModule;
10
11
  import com.facebook.react.bridge.ReactMethod;
12
+ import com.facebook.react.bridge.WritableMap;
11
13
  import com.facebook.react.module.annotations.ReactModule;
12
14
 
13
15
  import com.facebook.react.bridge.Callback;
@@ -42,7 +44,8 @@ public class ShieldFraudPluginModule extends ReactContextBaseJavaModule implemen
42
44
  return NAME;
43
45
  }
44
46
 
45
- private boolean isShieldInitialized() {
47
+ @ReactMethod(isBlockingSynchronousMethod = true)
48
+ public boolean isShieldInitialized() {
46
49
  try {
47
50
  return Shield.getInstance() != null;
48
51
  } catch (IllegalStateException e) {
@@ -120,17 +123,23 @@ public class ShieldFraudPluginModule extends ReactContextBaseJavaModule implemen
120
123
  }
121
124
 
122
125
  @ReactMethod
123
- public void setDeviceResultStateListener(Callback callback) {
126
+ public void setDeviceResultStateListener() {
124
127
  Shield.getInstance().setDeviceResultStateListener(new Shield.DeviceResultStateListener() {
125
128
  @Override
126
129
  public void isReady() {
127
- // Invoke the callback when the device is ready
128
- callback.invoke();
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);
129
137
  }
130
138
  });
131
139
  }
132
140
 
133
141
 
142
+
134
143
  @ReactMethod(isBlockingSynchronousMethod = true)
135
144
  public String getSessionId() {
136
145
  return Shield.getInstance().getSessionId();
@@ -161,13 +170,7 @@ public class ShieldFraudPluginModule extends ReactContextBaseJavaModule implemen
161
170
  for (Map.Entry<String, Object> entry : json.toHashMap().entrySet()) {
162
171
  data.put(entry.getKey(), (String) entry.getValue());
163
172
  }
164
- Shield.getInstance().setDeviceResultStateListener(new Shield.DeviceResultStateListener(){
165
- // check whether device fingerprinting is completed
166
- @Override
167
- public void isReady() {
168
- Shield.getInstance().sendAttributes(screenName, data);
169
- }
170
- });
173
+ Shield.getInstance().sendAttributes(screenName, data);
171
174
  }
172
175
 
173
176
  @ReactMethod
@@ -34,6 +34,10 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(getSessionId) {
34
34
  return [[Shield shared]sessionId];
35
35
  }
36
36
 
37
+ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(isShieldInitialized) {
38
+ return @(isShieldInitialized);
39
+ }
40
+
37
41
  // get device result to shield
38
42
  RCT_EXPORT_METHOD(getLatestDeviceResult:(RCTResponseSenderBlock)successCallback errorCallback: (RCTResponseSenderBlock)errorCallback)
39
43
  {
@@ -48,20 +52,15 @@ RCT_EXPORT_METHOD(getLatestDeviceResult:(RCTResponseSenderBlock)successCallback
48
52
  }
49
53
  }
50
54
 
51
- RCT_EXPORT_METHOD(setDeviceResultStateListener:(RCTResponseSenderBlock)callback)
55
+ RCT_EXPORT_METHOD(setDeviceResultStateListener)
52
56
  {
53
-
54
- NSTimeInterval delayInSeconds = 2.0;
55
- dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
56
- dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
57
- [[Shield shared] setDeviceResultStateListener:^{
58
- callback(@[]);
59
- }];
60
- });
57
+ [[Shield shared] setDeviceResultStateListener:^{
58
+ [self sendEventWithName:@"device_result_state" body:@{@"status": @"isSDKReady"}];
59
+ }];
61
60
  }
62
61
 
63
62
  - (NSArray<NSString *> *)supportedEvents {
64
- return @[@"success", @"error"];
63
+ return @[@"success", @"error", @"device_result_state"];
65
64
  }
66
65
 
67
66
  - (void)didErrorWithError:(NSError *)error
@@ -7,7 +7,7 @@
7
7
  <key>ShieldFraudPlugin.xcscheme_^#shared#^_</key>
8
8
  <dict>
9
9
  <key>orderHint</key>
10
- <integer>2</integer>
10
+ <integer>0</integer>
11
11
  </dict>
12
12
  </dict>
13
13
  </dict>
@@ -59,7 +59,7 @@ class ShieldFraud {
59
59
  * @param config - The configuration object containing the required properties.
60
60
  * @param callbacks - (Optional) The callback functions for success and failure events.
61
61
  */
62
- static initShield(config, callbacks) {
62
+ static async initShield(config, callbacks) {
63
63
  const isOptimizedListener = !!callbacks;
64
64
 
65
65
  // Set default values if logLevel is not provided
@@ -69,7 +69,7 @@ class ShieldFraud {
69
69
  const environmentInfo = config.environmentInfo || EnvironmentInfo.EnvironmentProd;
70
70
 
71
71
  // Call the native method to initialize ShieldFraud with the provided configuration.
72
- ShieldFraud.PlatformWrapper.initShield(config.siteID, config.secretKey, isOptimizedListener, config.blockedDialog, logLevel, environmentInfo);
72
+ await ShieldFraud.PlatformWrapper.initShield(config.siteID, config.secretKey, isOptimizedListener, config.blockedDialog, logLevel, environmentInfo);
73
73
  if (isOptimizedListener ?? false) {
74
74
  // Set up listeners for success and error events if callbacks are provided.
75
75
  ShieldFraud.listeners(callbacks);
@@ -107,15 +107,39 @@ class ShieldFraud {
107
107
  }
108
108
 
109
109
  /**
110
- * Checks if the ShieldFraud SDK is ready and invokes the provided callback with the
111
- * readiness state.
110
+ * Checks whether the ShieldFraud plugin is initialized.
112
111
  *
113
- * @param callback - The callback function to be invoked with the readiness state.
114
- */
115
- static isSDKready(callback) {
116
- ShieldFraud.PlatformWrapper.setDeviceResultStateListener(() => {
117
- callback(true);
118
- });
112
+ * @returns A Promise that resolves with a boolean value indicating whether the ShieldFraud plugin is initialized (true) or not (false).
113
+ */
114
+ static isShieldInitialized() {
115
+ return ShieldFraud.PlatformWrapper.isShieldInitialized();
116
+ }
117
+
118
+ /**
119
+ * Checks if the ShieldFraud SDK is ready and invokes the provided callback with the readiness state.
120
+ *
121
+ * @param callback - A callback function to be invoked with the readiness state.
122
+ * - `isReady` (boolean): A boolean value indicating whether the ShieldFraud SDK is ready.
123
+ */
124
+ static async isSDKready(callback) {
125
+ try {
126
+ const isInitialized = await this.isShieldInitialized();
127
+ if (!isInitialized) {
128
+ callback(false);
129
+ return;
130
+ }
131
+ const deviceResultListener = event => {
132
+ if (event.status === 'isSDKReady') {
133
+ ShieldFraud.eventEmitter.removeAllListeners('device_result_state');
134
+ callback(true);
135
+ }
136
+ };
137
+ ShieldFraud.eventEmitter.addListener('device_result_state', deviceResultListener);
138
+ ShieldFraud.PlatformWrapper.setDeviceResultStateListener();
139
+ } catch (error) {
140
+ console.error("An error occurred:", error);
141
+ callback(false);
142
+ }
119
143
  }
120
144
 
121
145
  /**
@@ -1 +1 @@
1
- {"version":3,"names":["_reactNative","require","LogLevel","exports","EnvironmentInfo","ShieldFraud","PlatformWrapper","NativeModules","ShieldFraudPlugin","eventEmitter","NativeEventEmitter","initShield","config","callbacks","isOptimizedListener","logLevel","LogLevelNone","environmentInfo","EnvironmentProd","siteID","secretKey","blockedDialog","listeners","addListener","data","onSuccess","error","onFailure","getSessionId","isSDKready","callback","setDeviceResultStateListener","sendAttributes","screenName","getLatestDeviceResult","Promise","resolve","reject","result","_default","default"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA;AACA;AACA;AAFA,IAGYC,QAAQ,0BAARA,QAAQ;EAARA,QAAQ,CAARA,QAAQ;EAARA,QAAQ,CAARA,QAAQ;EAARA,QAAQ,CAARA,QAAQ;EAAA,OAARA,QAAQ;AAAA;AAMpB;AACA;AACA;AAFAC,OAAA,CAAAD,QAAA,GAAAA,QAAA;AAAA,IAGYE,eAAe,0BAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAA,OAAfA,eAAe;AAAA;AAM3B;AACA;AACA;AAYA;AACA;AACA;AAGA;AACA;AACA;AAGA;AACA;AACA;AAFAD,OAAA,CAAAC,eAAA,GAAAA,eAAA;AAQA;AACA;AACA;AACA;AACA;AACA,MAAMC,WAAW,CAAC;EAChB;AACF;AACA;EACE,OAAeC,eAAe,GAAGC,0BAAa,CAACC,iBAAiB;;EAEhE;AACF;AACA;EACE,OAAeC,YAAY,GAAG,IAAIC,+BAAkB,CAACL,WAAW,CAACC,eAAe,CAAC;;EAEjF;AACF;AACA;AACA;AACA;AACA;EACE,OAAcK,UAAUA,CAACC,MAAc,EAAEC,SAA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AAC;IAChB,CAAC,CAAC;EACJ;;EAEA;AACF;AACA;AACA;AACA;AACA;EACE,OAAcE,cAAcA,CAACC,UAAkB,EAAET,IAAY,EAAQ;IACnEnB,WAAW,CAACC,eAAe,CAAC0B,cAAc,CAACC,UAAU,EAAET,IAAI,CAAC;EAC9D;;EAEA;AACF;AACA;AACA;AACA;EACE,OAAcU,qBAAqBA,CAAA,EAAoB;IACrD,OAAO,IAAIC,OAAO,CAAC,CAACC,OAAO,EAAEC,MAAM,KAAK;MACtChC,WAAW,CAACC,eAAe,CAAC4B,qBAAqB,CAC9CI,MAAc,IAAK;QAClB;QACAF,OAAO,CAACE,MAAM,CAAC;MACjB,CAAC,EACAZ,KAAa,IAAK;QACjB;QACAW,MAAM,CAACX,KAAK,CAAC;MACf,CAAC,CACF;IACH,CAAC,CAAC;EACJ;AACF;AAAC,IAAAa,QAAA,GAEclC,WAAW;AAAAF,OAAA,CAAAqC,OAAA,GAAAD,QAAA"}
1
+ {"version":3,"names":["_reactNative","require","LogLevel","exports","EnvironmentInfo","ShieldFraud","PlatformWrapper","NativeModules","ShieldFraudPlugin","eventEmitter","NativeEventEmitter","initShield","config","callbacks","isOptimizedListener","logLevel","LogLevelNone","environmentInfo","EnvironmentProd","siteID","secretKey","blockedDialog","listeners","addListener","data","onSuccess","error","onFailure","getSessionId","isShieldInitialized","isSDKready","callback","isInitialized","deviceResultListener","event","status","removeAllListeners","setDeviceResultStateListener","console","sendAttributes","screenName","getLatestDeviceResult","Promise","resolve","reject","result","_default","default"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA;AACA;AACA;AAFA,IAGYC,QAAQ,0BAARA,QAAQ;EAARA,QAAQ,CAARA,QAAQ;EAARA,QAAQ,CAARA,QAAQ;EAARA,QAAQ,CAARA,QAAQ;EAAA,OAARA,QAAQ;AAAA;AAMpB;AACA;AACA;AAFAC,OAAA,CAAAD,QAAA,GAAAA,QAAA;AA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,UAAkB,EAAEhB,IAAY,EAAQ;IACnEnB,WAAW,CAACC,eAAe,CAACiC,cAAc,CAACC,UAAU,EAAEhB,IAAI,CAAC;EAC9D;;EAEA;AACF;AACA;AACA;AACA;EACE,OAAciB,qBAAqBA,CAAA,EAAoB;IACrD,OAAO,IAAIC,OAAO,CAAC,CAACC,OAAO,EAAEC,MAAM,KAAK;MACtCvC,WAAW,CAACC,eAAe,CAACmC,qBAAqB,CAC9CI,MAAc,IAAK;QAClB;QACAF,OAAO,CAACE,MAAM,CAAC;MACjB,CAAC,EACAnB,KAAa,IAAK;QACjB;QACAkB,MAAM,CAAClB,KAAK,CAAC;MACf,CAAC,CACF;IACH,CAAC,CAAC;EACJ;AACF;AAAC,IAAAoB,QAAA,GAEczC,WAAW;AAAAF,OAAA,CAAA4C,OAAA,GAAAD,QAAA"}
@@ -58,7 +58,7 @@ class ShieldFraud {
58
58
  * @param config - The configuration object containing the required properties.
59
59
  * @param callbacks - (Optional) The callback functions for success and failure events.
60
60
  */
61
- static initShield(config, callbacks) {
61
+ static async initShield(config, callbacks) {
62
62
  const isOptimizedListener = !!callbacks;
63
63
 
64
64
  // Set default values if logLevel is not provided
@@ -68,7 +68,7 @@ class ShieldFraud {
68
68
  const environmentInfo = config.environmentInfo || EnvironmentInfo.EnvironmentProd;
69
69
 
70
70
  // Call the native method to initialize ShieldFraud with the provided configuration.
71
- ShieldFraud.PlatformWrapper.initShield(config.siteID, config.secretKey, isOptimizedListener, config.blockedDialog, logLevel, environmentInfo);
71
+ await ShieldFraud.PlatformWrapper.initShield(config.siteID, config.secretKey, isOptimizedListener, config.blockedDialog, logLevel, environmentInfo);
72
72
  if (isOptimizedListener ?? false) {
73
73
  // Set up listeners for success and error events if callbacks are provided.
74
74
  ShieldFraud.listeners(callbacks);
@@ -106,15 +106,39 @@ class ShieldFraud {
106
106
  }
107
107
 
108
108
  /**
109
- * Checks if the ShieldFraud SDK is ready and invokes the provided callback with the
110
- * readiness state.
109
+ * Checks whether the ShieldFraud plugin is initialized.
111
110
  *
112
- * @param callback - The callback function to be invoked with the readiness state.
113
- */
114
- static isSDKready(callback) {
115
- ShieldFraud.PlatformWrapper.setDeviceResultStateListener(() => {
116
- callback(true);
117
- });
111
+ * @returns A Promise that resolves with a boolean value indicating whether the ShieldFraud plugin is initialized (true) or not (false).
112
+ */
113
+ static isShieldInitialized() {
114
+ return ShieldFraud.PlatformWrapper.isShieldInitialized();
115
+ }
116
+
117
+ /**
118
+ * Checks if the ShieldFraud SDK is ready and invokes the provided callback with the readiness state.
119
+ *
120
+ * @param callback - A callback function to be invoked with the readiness state.
121
+ * - `isReady` (boolean): A boolean value indicating whether the ShieldFraud SDK is ready.
122
+ */
123
+ static async isSDKready(callback) {
124
+ try {
125
+ const isInitialized = await this.isShieldInitialized();
126
+ if (!isInitialized) {
127
+ callback(false);
128
+ return;
129
+ }
130
+ const deviceResultListener = event => {
131
+ if (event.status === 'isSDKReady') {
132
+ ShieldFraud.eventEmitter.removeAllListeners('device_result_state');
133
+ callback(true);
134
+ }
135
+ };
136
+ ShieldFraud.eventEmitter.addListener('device_result_state', deviceResultListener);
137
+ ShieldFraud.PlatformWrapper.setDeviceResultStateListener();
138
+ } catch (error) {
139
+ console.error("An error occurred:", error);
140
+ callback(false);
141
+ }
118
142
  }
119
143
 
120
144
  /**
@@ -1 +1 @@
1
- {"version":3,"names":["NativeModules","NativeEventEmitter","LogLevel","EnvironmentInfo","ShieldFraud","PlatformWrapper","ShieldFraudPlugin","eventEmitter","initShield","config","callbacks","isOptimizedListener","logLevel","LogLevelNone","environmentInfo","EnvironmentProd","siteID","secretKey","blockedDialog","listeners","addListener","data","onSuccess","error","onFailure","getSessionId","isSDKready","callback","setDeviceResultStateListener","sendAttributes","screenName","getLatestDeviceResult","Promise","resolve","reject","result"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":"AAAA,SAASA,aAAa,EAAEC,kBAAkB,QAAQ,cAAc;;AAEhE;AACA;AACA;AACA,WAAYC,QAAQ,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;MACxD,IAAIX,SAAS,aAATA,SAAS,eAATA,SAAS,CAAEY,SAAS,EAAE;QACxBZ,SAAS,CAACY,SAAS,CAACD,IAAI,CAAC;MAC3B;IACF,CAAC,CAAC;;IAEF;IACAjB,WAAW,CAACG,YAAY,CAACa,WAAW,CAAC,OAAO,EAAGG,KAAK,IAAK;MACvD,IAAIb,SAAS,aAATA,SAAS,eAATA,SAAS,CAAEc,SAAS,EAAE;QACxBd,SAAS,CAACc,SAAS,CAACD,KAAK,CAAC;MAC5B;IACF,CAAC,CAAC;EACJ;;EAEA;AACF;AACA;AACA;AACA;EACE,OAAcE,YAAYA,CAAA,EAAoB;IAC5C,OAAOrB,WAAW,CAACC,eAAe,CAACoB,YAAY,EAAE;EACnD;;EAEA;AACF;AACA;AACA;AACA;AACA;EACE,OAAcC,UAAUA,CAACC,QAAoC,EAAQ;IACnEvB,WAAW,CAACC,eAAe,CAACuB,4BAA4B,CAAC,MAAM;MAC7DD,QAAQ,CAAC,IAAI,CAAC;IAChB,CAAC,CAAC;EACJ;;EAEA;AACF;AACA;AACA;AACA;AACA;EACE,OAAcE,cAAcA,CAACC,UAAkB,EAAET,IAAY,EAAQ;IACnEjB,WAAW,CAACC,eAAe,CAACwB,cAAc,CAACC,UAAU,EAAET,IAAI,CAAC;EAC9D;;EAEA;AACF;AACA;AACA;AACA;EACE,OAAcU,qBAAqBA,CAAA,EAAoB;IACrD,OAAO,IAAIC,OAAO,CAAC,CAACC,OAAO,EAAEC,MAAM,KAAK;MACtC9B,WAAW,CAACC,eAAe,CAAC0B,qBAAqB,CAC9CI,MAAc,IAAK;QAClB;QACAF,OAAO,CAACE,MAAM,CAAC;MACjB,CAAC,EACAZ,KAAa,IAAK;QACjB;QACAW,MAAM,CAACX,KAAK,CAAC;MACf,CAAC,CACF;IACH,CAAC,CAAC;EACJ;AACF;AAEA,eAAenB,WAAW"}
1
+ {"version":3,"names":["NativeModules","NativeEventEmitter","LogLevel","EnvironmentInfo","ShieldFraud","PlatformWrapper","ShieldFraudPlugin","eventEmitter","initShield","config","callbacks","isOptimizedListener","logLevel","LogLevelNone","environmentInfo","EnvironmentProd","siteID","secretKey","blockedDialog","listeners","addListener","data","onSuccess","error","onFailure","getSessionId","isShieldInitialized","isSDKready","callback","isInitialized","deviceResultListener","event","status","removeAllListeners","setDeviceResultStateListener","console","sendAttributes","screenName","getLatestDeviceResult","Promise","resolve","reject","result"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":"AAAA,SAASA,aAAa,EAAEC,kBAAkB,QAAQ,cAAc;;AAEhE;AACA;AACA;AACA,WAAYC,QAAQ,0BAARA,QAAQ;EAARA,QAAQ,CAARA,QAAQ;EAARA,QAAQ,CAARA,QAAQ;EAARA,QAAQ,CAARA,QAAQ;EAAA,OAARA,QAAQ;AAAA;;AAMpB;AACA;AACA;AACA,WAAYC,eAAe,0BAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAA,OAAfA,eAAe;AAAA;;AAM3B;AACA;AACA;;AAYA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA;AACA,MAAMC,WAAW,CAAC;EAChB;AACF;AACA;EACE,OAAeC,eAAe,GAAGL,aAAa,CAACM,iBAAiB;;EAEhE;AACF;AACA;EACE,OAAeC,YAAY,GAAG,IAAIN,kBAAkB,CAACG,WAAW,CAACC,eAAe,CAAC;;EAEjF;AACF;AACA;AACA;AACA;AACA;EACE,aAAoBG,UAAUA,CAACC,MAAc,EAAEC,SAA0B,EAAiB;IACxF,MAAMC,mBAAmB,GAAG,CAAC,CAACD,SAAS;;IAEvC;IACA,MAAME,QAAQ,GAAGH,MAAM,CAACG,QAAQ,IAAIV,QAAQ,CAACW,YAAY;;IAEzD;IACA,MAAMC,eAAe,GAAGL,MAAM,CAACK,eAAe,IAAIX,eAAe,CAACY,eAAe;;IAEjF;IACA,MAAMX,WAAW,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AAIA,KAAK,CAACC,MAAM,KAAK,YAAY,EAAE;UACjC5B,WAAW,CAACG,YAAY,CAAC0B,kBAAkB,CAAC,qBAAqB,CAAC;UAClEL,QAAQ,CAAC,IAAI,CAAC;QAChB;MACF,CAAC;MAEDxB,WAAW,CAACG,YAAY,CAACa,WAAW,CAAC,qBAAqB,EAAEU,oBAAoB,CAAC;MACjF1B,WAAW,CAACC,eAAe,CAAC6B,4BAA4B,EAAE;IAC5D,CAAC,CAAC,OAAOX,KAAK,EAAE;MACdY,OAAO,CAACZ,KAAK,CAAC,oBAAoB,EAAEA,KAAK,CAAC;MAC1CK,QAAQ,CAAC,KAAK,CAAC;IACjB;EACF;;EAGA;AACF;AACA;AACA;AACA;AACA;EACE,OAAcQ,cAAcA,CAACC,UAAkB,EAAEhB,IAAY,EAAQ;IACnEjB,WAAW,CAACC,eAAe,CAAC+B,cAAc,CAACC,UAAU,EAAEhB,IAAI,CAAC;EAC9D;;EAEA;AACF;AACA;AACA;AACA;EACE,OAAciB,qBAAqBA,CAAA,EAAoB;IACrD,OAAO,IAAIC,OAAO,CAAC,CAACC,OAAO,EAAEC,MAAM,KAAK;MACtCrC,WAAW,CAACC,eAAe,CAACiC,qBAAqB,CAC9CI,MAAc,IAAK;QAClB;QACAF,OAAO,CAACE,MAAM,CAAC;MACjB,CAAC,EACAnB,KAAa,IAAK;QACjB;QACAkB,MAAM,CAAClB,KAAK,CAAC;MACf,CAAC,CACF;IACH,CAAC,CAAC;EACJ;AACF;AAEA,eAAenB,WAAW"}
@@ -62,7 +62,7 @@ declare class ShieldFraud {
62
62
  * @param config - The configuration object containing the required properties.
63
63
  * @param callbacks - (Optional) The callback functions for success and failure events.
64
64
  */
65
- static initShield(config: Config, callbacks?: ShieldCallback): void;
65
+ static initShield(config: Config, callbacks?: ShieldCallback): Promise<void>;
66
66
  /**
67
67
  * Sets up event listeners for success and error events.
68
68
  *
@@ -76,12 +76,18 @@ declare class ShieldFraud {
76
76
  */
77
77
  static getSessionId(): Promise<string>;
78
78
  /**
79
- * Checks if the ShieldFraud SDK is ready and invokes the provided callback with the
80
- * readiness state.
79
+ * Checks whether the ShieldFraud plugin is initialized.
81
80
  *
82
- * @param callback - The callback function to be invoked with the readiness state.
83
- */
84
- static isSDKready(callback: (isReady: boolean) => void): void;
81
+ * @returns A Promise that resolves with a boolean value indicating whether the ShieldFraud plugin is initialized (true) or not (false).
82
+ */
83
+ static isShieldInitialized(): Promise<Boolean>;
84
+ /**
85
+ * Checks if the ShieldFraud SDK is ready and invokes the provided callback with the readiness state.
86
+ *
87
+ * @param callback - A callback function to be invoked with the readiness state.
88
+ * - `isReady` (boolean): A boolean value indicating whether the ShieldFraud SDK is ready.
89
+ */
90
+ static isSDKready(callback: (isReady: boolean) => void): Promise<void>;
85
91
  /**
86
92
  * Sends attributes to the ShieldFraud plugin for a specific screen.
87
93
  *
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAEA;;GAEG;AACH,oBAAY,QAAQ;IAClB,aAAa,IAAI;IACjB,YAAY,IAAI;IAChB,YAAY,IAAI;CACjB;AAED;;GAEG;AACH,oBAAY,eAAe;IACzB,eAAe,IAAI;IACnB,cAAc,IAAI;IAClB,eAAe,IAAI;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE;QACd,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;KACd,GAAG,IAAI,CAAC;IACT,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,eAAe,CAAC,EAAE,eAAe,CAAC;CACnC;AAED;;GAEG;AACH,KAAK,eAAe,GAAG,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,CAAC;AAE3C;;GAEG;AACH,KAAK,eAAe,GAAG,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAA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,QAAQ,CAAC;IACpB,eAAe,CAAC,EAAE,eAAe,CAAC;CACnC;AAED;;GAEG;AACH,KAAK,eAAe,GAAG,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,CAAC;AAE3C;;GAEG;AACH,KAAK,eAAe,GAAG,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC;AAE5C;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,SAAS,CAAC,EAAE,eAAe,CAAC;IAC5B,SAAS,CAAC,EAAE,eAAe,CAAC;CAC7B,CAAC;AAEF;;;;GAIG;AACH,cAAM,WAAW;IACf;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,eAAe,CAAmC;IAEjE;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,YAAY,CAAuD;IAElF;;;;;OAKG;WACiB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAyBzF;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,SAAS;IAgBxB;;;;OAIG;WACW,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC;IAI7C;;;;MAIE;WACY,mBAAmB,IAAI,OAAO,CAAC,OAAO,CAAC;IAIrD;;;;;MAKE;WACkB,UAAU,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAyBnF;;;;;OAKG;WACW,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI;IAIpE;;;;OAIG;WACW,qBAAqB,IAAI,OAAO,CAAC,MAAM,CAAC;CAcvD;AAED,eAAe,WAAW,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-shield-fraud-plugin",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
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",
package/src/index.tsx CHANGED
@@ -72,17 +72,17 @@ class ShieldFraud {
72
72
  * @param config - The configuration object containing the required properties.
73
73
  * @param callbacks - (Optional) The callback functions for success and failure events.
74
74
  */
75
- public static initShield(config: Config, callbacks?: ShieldCallback): void {
75
+ public static async initShield(config: Config, callbacks?: ShieldCallback): Promise<void> {
76
76
  const isOptimizedListener = !!callbacks;
77
77
 
78
- // Set default values if logLevel is not provided
78
+ // Set default values if logLevel is not provided
79
79
  const logLevel = config.logLevel || LogLevel.LogLevelNone;
80
80
 
81
81
  // Set default values if environmentInfo is not provided
82
82
  const environmentInfo = config.environmentInfo || EnvironmentInfo.EnvironmentProd;
83
83
 
84
84
  // Call the native method to initialize ShieldFraud with the provided configuration.
85
- ShieldFraud.PlatformWrapper.initShield(
85
+ await ShieldFraud.PlatformWrapper.initShield(
86
86
  config.siteID,
87
87
  config.secretKey,
88
88
  isOptimizedListener,
@@ -128,16 +128,44 @@ class ShieldFraud {
128
128
  }
129
129
 
130
130
  /**
131
- * Checks if the ShieldFraud SDK is ready and invokes the provided callback with the
132
- * readiness state.
131
+ * Checks whether the ShieldFraud plugin is initialized.
133
132
  *
134
- * @param callback - The callback function to be invoked with the readiness state.
135
- */
136
- public static isSDKready(callback: (isReady: boolean) => void): void {
137
- ShieldFraud.PlatformWrapper.setDeviceResultStateListener(() => {
138
- callback(true);
139
- });
133
+ * @returns A Promise that resolves with a boolean value indicating whether the ShieldFraud plugin is initialized (true) or not (false).
134
+ */
135
+ public static isShieldInitialized(): Promise<Boolean> {
136
+ return ShieldFraud.PlatformWrapper.isShieldInitialized();
137
+ }
138
+
139
+ /**
140
+ * Checks if the ShieldFraud SDK is ready and invokes the provided callback with the readiness state.
141
+ *
142
+ * @param callback - A callback function to be invoked with the readiness state.
143
+ * - `isReady` (boolean): A boolean value indicating whether the ShieldFraud SDK is ready.
144
+ */
145
+ public static async isSDKready(callback: (isReady: boolean) => void): Promise<void> {
146
+ try {
147
+ const isInitialized = await this.isShieldInitialized();
148
+
149
+ if (!isInitialized) {
150
+ callback(false);
151
+ return;
152
+ }
153
+
154
+ const deviceResultListener = (event: { status: string }) => {
155
+ if (event.status === 'isSDKReady') {
156
+ ShieldFraud.eventEmitter.removeAllListeners('device_result_state');
157
+ callback(true);
158
+ }
159
+ };
160
+
161
+ ShieldFraud.eventEmitter.addListener('device_result_state', deviceResultListener);
162
+ ShieldFraud.PlatformWrapper.setDeviceResultStateListener();
163
+ } catch (error) {
164
+ console.error("An error occurred:", error);
165
+ callback(false);
166
+ }
140
167
  }
168
+
141
169
 
142
170
  /**
143
171
  * Sends attributes to the ShieldFraud plugin for a specific screen.