react-native-shield-fraud-plugin 1.0.11 → 2.0.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.
package/src/index.tsx CHANGED
@@ -1,9 +1,23 @@
1
- import { NativeModules, NativeEventEmitter } from "react-native";
1
+ import {
2
+ NativeModules,
3
+ NativeEventEmitter,
4
+ Platform,
5
+ TurboModuleRegistry,
6
+ } from "react-native";
7
+
8
+ /**
9
+ * Resolve the native module through TurboModuleRegistry (New Architecture)
10
+ * with a fallback to NativeModules bridge (Old Architecture).
11
+ */
12
+ const ShieldFraudPluginNativeModule =
13
+ TurboModuleRegistry.get<any>("ShieldFraudPlugin") ??
14
+ NativeModules.ShieldFraudPlugin;
2
15
 
3
16
  /**
4
17
  * Enum representing the log levels for ShieldFraud.
5
18
  */
6
19
  export enum LogLevel {
20
+ LogLevelVerbose = 4,
7
21
  LogLevelDebug = 3,
8
22
  LogLevelInfo = 2,
9
23
  LogLevelNone = 1,
@@ -13,9 +27,9 @@ export enum LogLevel {
13
27
  * Enum representing the environment information for ShieldFraud.
14
28
  */
15
29
  export enum EnvironmentInfo {
16
- EnvironmentProd = 0,
17
- EnvironmentDev = 1,
18
- EnvironmentStag = 2,
30
+ EnvironmentProd = 0, // Environment.PROD
31
+ EnvironmentDev = 1, // Environment.DEV
32
+ EnvironmentStaging = 2, // Environment.STAGING
19
33
  }
20
34
 
21
35
  /**
@@ -30,6 +44,12 @@ export interface Config {
30
44
  } | null;
31
45
  logLevel?: LogLevel;
32
46
  environmentInfo?: EnvironmentInfo;
47
+ /**
48
+ * Android-only: when true, the Shield SDK will block screen recording
49
+ * while it is active. Has no effect on iOS (the value is forwarded but
50
+ * the native side ignores it). Defaults to false when not provided.
51
+ */
52
+ blockScreenRecording?: boolean;
33
53
  }
34
54
 
35
55
  /**
@@ -58,8 +78,10 @@ export type ShieldCallback = {
58
78
  class ShieldFraud {
59
79
  /**
60
80
  * The native module for accessing the ShieldFraudPlugin.
81
+ * Resolved via TurboModuleRegistry on New Architecture, with
82
+ * a NativeModules bridge fallback for Old Architecture.
61
83
  */
62
- private static PlatformWrapper = NativeModules.ShieldFraudPlugin;
84
+ private static PlatformWrapper = ShieldFraudPluginNativeModule;
63
85
 
64
86
  /**
65
87
  * The event emitter for listening to success and error events.
@@ -90,14 +112,21 @@ class ShieldFraud {
90
112
  // Set cross-platform parameters internally (React Native and version from package.json)
91
113
  ShieldFraud.setCrossPlatformParameters();
92
114
 
115
+ // blockScreenRecording is Android-only; iOS native ignores the value.
116
+ // Always send a real boolean — the Old Arch bridge cannot handle null
117
+ // for boolean parameters (causes NPE in ReadableNativeArray.getBoolean).
118
+ const blockScreenRecording =
119
+ Platform.OS === "android" ? (config.blockScreenRecording ?? false) : false;
120
+
93
121
  // Call the native method to initialize ShieldFraud with the provided configuration.
94
122
  await ShieldFraud.PlatformWrapper.initShield(
95
123
  config.siteID,
96
124
  config.secretKey,
97
125
  isOptimizedListener,
98
- config.blockedDialog,
126
+ config.blockedDialog ?? null,
99
127
  logLevel,
100
- environmentInfo
128
+ environmentInfo,
129
+ blockScreenRecording
101
130
  );
102
131
 
103
132
  if (isOptimizedListener) {
@@ -112,7 +141,7 @@ class ShieldFraud {
112
141
  */
113
142
  private static setCrossPlatformParameters(): void {
114
143
  const crossPlatformName = "react-native-shield-fraud-plugin";
115
- const crossPlatformVersion = "1.0.11";
144
+ const crossPlatformVersion = "2.0.0";
116
145
 
117
146
  ShieldFraud.PlatformWrapper.setCrossPlatformParameters(
118
147
  crossPlatformName,
@@ -160,14 +189,25 @@ class ShieldFraud {
160
189
  }
161
190
 
162
191
  /**
163
- * Checks if the ShieldFraud SDK is ready and invokes the provided callback with the readiness state.
192
+ * iOS only — checks if the ShieldFraud SDK is ready and invokes the provided
193
+ * callback with the readiness state.
194
+ *
195
+ * On Android (SDK 2.x) device result events fire automatically via the
196
+ * Sentinel inside createShieldWithCallback. There is no subscription call
197
+ * and no reliable way to intercept the event after the fact, so this method
198
+ * is a no-op on Android. Use the `callbacks` parameter of `initShield`
199
+ * instead to receive device results on Android.
164
200
  *
165
201
  * @param callback - A callback function to be invoked with the readiness state.
166
- * - `isReady` (boolean): A boolean value indicating whether the ShieldFraud SDK is ready.
202
+ * - `isReady` (boolean): true when the SDK has produced a device result.
167
203
  */
168
204
  public static async isSDKready(
169
205
  callback: (isReady: boolean) => void
170
206
  ): Promise<void> {
207
+ if (Platform.OS !== "ios") {
208
+ return;
209
+ }
210
+
171
211
  try {
172
212
  // Adding a timeout of 100 milliseconds
173
213
  await new Promise((resolve) => setTimeout(resolve, 100));
@@ -191,6 +231,8 @@ class ShieldFraud {
191
231
  "device_result_state",
192
232
  deviceResultListener
193
233
  );
234
+
235
+ // Trigger the SDK subscription — iOS 1.x requires this explicit call.
194
236
  ShieldFraud.PlatformWrapper.setDeviceResultStateListener();
195
237
  } catch (error) {
196
238
  console.error("An error occurred:", error);
@@ -208,6 +250,31 @@ class ShieldFraud {
208
250
  ShieldFraud.PlatformWrapper.sendAttributes(screenName, data);
209
251
  }
210
252
 
253
+ /**
254
+ * Sends attributes and resolves with `true` when the native SDK confirms success.
255
+ *
256
+ * @param screenName - The name of the screen.
257
+ * @param data - The attribute data object.
258
+ * @returns A Promise that resolves to true on success and rejects on error.
259
+ */
260
+ public static sendAttributesWithCallback(
261
+ screenName: string,
262
+ data: object
263
+ ): Promise<boolean> {
264
+ return new Promise((resolve, reject) => {
265
+ ShieldFraud.PlatformWrapper.sendAttributesWithCallback(
266
+ screenName,
267
+ data,
268
+ (result: boolean) => {
269
+ resolve(!!result);
270
+ },
271
+ (error: object) => {
272
+ reject(error);
273
+ }
274
+ );
275
+ });
276
+ }
277
+
211
278
  /**
212
279
  * Retrieves the latest device result from the ShieldFraud plugin.
213
280
  *
@@ -217,11 +284,31 @@ class ShieldFraud {
217
284
  return new Promise((resolve, reject) => {
218
285
  ShieldFraud.PlatformWrapper.getLatestDeviceResult(
219
286
  (result: object) => {
220
- // Handle success with the result object
221
287
  resolve(result);
222
288
  },
223
289
  (error: object) => {
224
- // Handle error with the error object
290
+ reject(error);
291
+ }
292
+ );
293
+ });
294
+ }
295
+
296
+ /**
297
+ * Triggers a device signature computation for a given screen name.
298
+ * On success, resolves with the latest device result object.
299
+ * On failure, rejects with the error message.
300
+ *
301
+ * @param screenName - The name of the screen triggering the signature.
302
+ * @returns A Promise that resolves with the device result or rejects with an error.
303
+ */
304
+ public static sendDeviceSignature(screenName: string): Promise<object> {
305
+ return new Promise((resolve, reject) => {
306
+ ShieldFraud.PlatformWrapper.sendDeviceSignature(
307
+ screenName,
308
+ (result: object) => {
309
+ resolve(result);
310
+ },
311
+ (error: string) => {
225
312
  reject(error);
226
313
  }
227
314
  );
@@ -1,106 +0,0 @@
1
- #import "ShieldFraudPlugin.h"
2
-
3
- @implementation ShieldFraudPlugin
4
-
5
- static BOOL isShieldInitialized = NO;
6
-
7
- RCT_EXPORT_MODULE();
8
-
9
- RCT_EXPORT_METHOD(initShield:(NSString *)siteID secretKey:(NSString *)secretKey isOptimizedListener:(BOOL)isOptimizedListener blockedDialog:(NSDictionary *)blockedDialog logLevel:(NSInteger)logLevel environmentInfo:(NSInteger)environmentInfo)
10
- {
11
- if (!isShieldInitialized) {
12
- Configuration *config = [[Configuration alloc] initWithSiteId:siteID secretKey:secretKey];
13
-
14
- if (isOptimizedListener) {
15
- config.deviceShieldCallback = self;
16
- }
17
-
18
- if (blockedDialog != nil) {
19
- NSString *title = [blockedDialog objectForKey:@"title"];
20
- NSString *body = [blockedDialog objectForKey:@"body"];
21
- config.defaultBlockedDialog = [[BlockedDialog alloc] initWithTitle:title body:body];
22
- }
23
-
24
- // Use logLevel parameter as needed
25
- config.logLevel = logLevel;
26
- config.environment = environmentInfo;
27
- [Shield setUpWith:config];
28
- isShieldInitialized = YES;
29
- }
30
- }
31
-
32
- // New method to set cross-platform parameters
33
- RCT_EXPORT_METHOD(setCrossPlatformParameters:(NSString *)crossPlatformName
34
- crossPlatformVersion:(NSString *)crossPlatformVersion)
35
- {
36
- ShieldCrossPlatformParams *params = [[ShieldCrossPlatformParams alloc] initWithName:crossPlatformName version:crossPlatformVersion];
37
- [ShieldCrossPlatformHelper setCrossPlatformParameters:params];
38
- }
39
-
40
- // get session id from shield sdk
41
- RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(getSessionId) {
42
- return [[Shield shared]sessionId];
43
- }
44
-
45
- RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(isShieldInitialized) {
46
- return @(isShieldInitialized);
47
- }
48
-
49
- // get device result to shield
50
- RCT_EXPORT_METHOD(getLatestDeviceResult:(RCTResponseSenderBlock)successCallback errorCallback: (RCTResponseSenderBlock)errorCallback)
51
- {
52
- NSDictionary<NSString *, id> *result = [[Shield shared] getLatestDeviceResult];
53
- if (result != NULL) {
54
- successCallback(@[result]);
55
- }
56
-
57
- NSError *error = [[Shield shared] getErrorResponse];
58
- if (error != NULL) {
59
- errorCallback(@[error]);
60
- }
61
- }
62
-
63
- RCT_EXPORT_METHOD(setDeviceResultStateListener)
64
- {
65
- double delayInSeconds = 1.5;
66
-
67
- dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
68
-
69
- dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
70
- [[Shield shared] setDeviceResultStateListener:^{
71
- [self sendEventWithName:@"device_result_state" body:@{@"status": @"isSDKReady"}];
72
- }];
73
- });
74
- }
75
-
76
-
77
- - (NSArray<NSString *> *)supportedEvents {
78
- return @[@"success", @"error", @"device_result_state"];
79
- }
80
-
81
- - (void)addListener:(NSString *)eventName {
82
- [super addListener:eventName];
83
- }
84
-
85
- - (void)removeListeners:(double)count {
86
- [super removeListeners:count];
87
- }
88
-
89
- - (void)didErrorWithError:(NSError *)error
90
- {
91
- [self sendEventWithName:@"error" body:[error localizedDescription]];
92
- }
93
-
94
- - (void)didSuccessWithResult:(NSDictionary<NSString *,id> *)result
95
- {
96
- [self sendEventWithName:@"success" body: result];
97
- }
98
-
99
- RCT_EXPORT_METHOD(sendAttributes: (NSString *)screenName data: (NSDictionary *)data)
100
- {
101
- [[Shield shared] sendAttributesWithScreenName:screenName data:data];
102
- }
103
- @end
104
-
105
-
106
-